<?php
/**
 * Created by PhpStorm.
 * User: guokunsheng
 * Date: 2024/9/10
 * Time: 下午1:14
 */

namespace app\common\lib\ziwei;

use app\common\lib\astrolog\Astrolog;
use app\common\lib\horoscope\Util;
use Exception;
use Overtrue\ChineseCalendar\Calendar;
use think\Log;

const ZW_ZIWEI = 0; // 紫微
const ZW_TIANJI = 1; // 天机
const ZW_TAIYANG = 2; // 太阳
const ZW_WUQU = 3; // 武曲
const ZW_TIANTONG = 4; // 天同
const ZW_LIANZHEN = 5; // 廉贞
const ZW_TIANFU = 6; // 天府
const ZW_TAIYIN = 7; // 太阴
const ZW_TANLANG = 8; // 贪狼
const ZW_JUMEN = 9; // 巨门
const ZW_TIANXIANG = 10; // 天相
const ZW_TIANLIANG = 11; // 天梁
const ZW_QISHA = 12; // 七杀
const ZW_POJUN = 13; // 破军
const ZW_WENCHANG = 14; // 文昌
const ZW_WENQU = 15; // 文曲
const ZW_ZUOFU = 16; // 左辅
const ZW_YOUBI = 17; // 右弼
const ZW_TIANKUI = 18; // 天魁
const ZW_TIANYUE = 19; // 天钺
const ZW_LUCUN = 20; // 禄存
const ZW_TIANMA = 21; // 天马
const ZW_QINGYANG = 22; // 擎羊
const ZW_TUOLUO = 23; // 陀罗
const ZW_HUOXING = 24; // 火星
const ZW_LINGXING = 25; // 铃星
const ZW_DIKONG = 26; // 地空
const ZW_DIJIE = 27; // 地劫

const ZW_TIANSHANG = 28; // 天伤
const ZW_TIANSHI = 29; // 天使
const ZW_TIANYAO = 30; // 天姚
const ZW_TIANXING = 31; // 天刑
const ZW_TIANKU = 32; // 天哭
const ZW_TIANXU = 33; // 天虚
const ZW_HONGLUAN = 34; // 红鸾
const ZW_TIANXI = 35; // 天喜
const ZW_SANTAI = 36; // 三台
const ZW_BAZUO = 37; // 八座
const ZW_LONGCHI = 38; // 龙池
const ZW_FENGGE = 39; // 凤阁
const ZW_TIANCAI = 40; // 天才
const ZW_TIANSHOU = 41; // 天寿
const ZW_ENGUANG = 42; // 恩光
const ZW_TIANGUI = 43; // 天贵
const ZW_TIANGUAN = 44; // 天官
const ZW_TIANFU2 = 45; // 天福
const ZW_TAIFU = 46; // 台辅
const ZW_FENGGAO = 47; // 封诰
const ZW_GUCHEN = 48; // 孤辰
const ZW_GUAXIU = 49; // 寡宿
const ZW_FEILIAN = 50; // 蜚廉
const ZW_POSUI = 51; // 破碎
const ZW_XIESHEN = 52; // 解神
const ZW_NIANXIE = 53; // 年解
const ZW_TIANWU = 54; // 天巫
const ZW_TIANYUE2 = 55; // 天月
const ZW_YINSHA = 56; // 阴煞
const ZW_JIEKONG = 57; // 截空
const ZW_FUJIE = 58; // 副截
const ZW_XUNKONG = 59; // 旬空
const ZW_FUXUN = 60; // 副旬
const ZW_TIANKONG = 61; // 天空
const ZW_TIANCHU = 62; // 天厨
const ZW_JIESHA = 63; // 劫煞
const ZW_TIANDE = 64; // 天德
const ZW_YUEDE = 65; // 月德
const ZW_HUAGAI = 66; // 华盖
const ZW_XIANCHI = 67; // 咸池
const ZW_DAHAO = 68; // 大耗

// 博士十二神
const BS_BOSHI = 0; // 博士
const BS_LISHI = 1; // 力士
const BS_QINGLONG = 2; // 青龙
const BS_XIAOHAO = 3; // 小耗
const BS_JIANGJUN = 4; // 将军
const BS_ZOUSHU = 5; // 奏书
const BS_FEILIAN = 6; // 飞廉
const BS_XISHEN = 7; // 喜神
const BS_BINGFU = 8; // 病符
const BS_DAHAO = 9; // 大耗
const BS_FUBING = 10; // 伏兵
const BS_GUANFU = 11; // 官符
// 长生十二神
const CS_CHANGSHENG = 0; // 长生
const CS_MUYU = 1; // 沐浴
const CS_GUANDAI = 2; // 冠带
const CS_LINGUAN = 3; // 临官
const CS_DIWANG = 4; // 帝旺
const CS_SHUAI = 5; // 衰
const CS_BING = 6; // 病
const CS_SI = 7; // 死
const CS_MU = 8; // 墓
const CS_JUE = 9; // 绝
const CS_TAI = 10; // 胎
const CS_YANG = 11; // 养
// 将前十二神
const JQ_JIANGXING = 0; // 将星
const JQ_PANAN = 1; // 攀鞍
const JQ_SUIYI = 2; // 岁驿
const JQ_XISHEN = 3; // 息神
const JQ_HUAGAI = 4; // 华盖
const JQ_JIESHA = 5; // 劫煞
const JQ_ZAISHA = 6; // 灾煞
const JQ_TIANSHA = 7; // 天煞
const JQ_ZHIBEI = 8; // 指背
const JQ_XIANCHI = 9; // 咸池
const JQ_YUESHA = 10; // 月煞
const JQ_WANGSHEN = 11; // 亡神
// 太岁十二神、岁前十二神
const TS_SUIJIAN = 0; // 岁建
const TS_HUIQI = 1; // 晦气
const TS_SANGMEN = 2; // 丧门
const TS_GUANSUO = 3; // 贯索
const TS_GUANFU = 4; // 官符
const TS_XIAOHAO = 5; // 小耗
const TS_DAHAO = 6; // 大耗
const TS_LONGDE = 7; // 龙德
const TS_BAIHU = 8; // 白虎
const TS_TIANDE = 9; // 天德
const TS_DIAOKE = 10; // 吊客
const TS_BINGFU = 11; // 病符


const TG_JIA = 0; // 甲
const TG_YI = 1; // 乙
const TG_BING = 2; // 丙
const TG_DING = 3; // 丁
const TG_WU = 4; // 戊
const TG_JI = 5; // 己
const TG_GENG = 6; // 庚
const TG_XIN = 7; // 辛
const TG_REN = 8; // 壬
const TG_GUI = 9; // 癸

const DZ_ZI = 0; // 子
const DZ_CHOU = 1; // 丑
const DZ_YIN = 2; // 寅
const DZ_MAO = 3; // 卯
const DZ_CHEN = 4; // 辰
const DZ_SI = 5; // 巳
const DZ_WU = 6; // 午
const DZ_WEI = 7; // 未
const DZ_SHEN = 8; // 申
const DZ_YOU = 9; // 酉
const DZ_XU = 10; // 戌
const DZ_HAI = 11; // 亥

const ZW_H1 = 0; // 命宫
const ZW_H2 = 1; // 兄弟
const ZW_H3 = 2; // 夫妻
const ZW_H4 = 3; // 子女
const ZW_H5 = 4; // 财帛
const ZW_H6 = 5; // 疾厄
const ZW_H7 = 6; // 迁移
const ZW_H8 = 7; // 奴仆
const ZW_H9 = 8; // 官禄
const ZW_H10 = 9; // 田宅
const ZW_H11 = 10; // 福德
const ZW_H12 = 11; // 父母

const WX_JIN = 0; // 金
const WX_MU = 1; // 木
const WX_SHUI = 2; // 水
const WX_HUO = 3; // 火
const WX_TU = 4; // 土

const SH_LU = 0; // 禄
const SH_QUAN = 1; // 权
const SH_KE = 2; // 科
const SH_JI = 3; // 忌

/**
 * 紫微斗数
 * 正曜：紫微天府等十四主星
 * 辅曜：左辅、右弼、天魁、天钺
 * 佐曜：文昌、文曲、禄存、天马
 * 煞曜：擎羊、陀罗、火星、铃星成为四煞，加上地空、地劫成为六煞
 * 空劫：地空、地劫
 * 化曜：化禄、化权、化科、化忌
 * 三奇：化禄、化权、化科
 * Class Ziwei
 * @package app\common\lib\ziwei
 */
class Ziwei
{
    // 12宫
    private $houseList = [
        ZW_H1 => '命宫', ZW_H2 => '兄弟', ZW_H3 => '夫妻', ZW_H4 => '子女', ZW_H5 => '财帛', ZW_H6 => '疾厄',
        ZW_H7 => '迁移', ZW_H8 => '交友', ZW_H9 => '官禄', ZW_H10 => '田宅', ZW_H11 => '福德', ZW_H12 => '父母'
    ];
    // 十天干
    private $tiangan = [
        TG_JIA => '甲', TG_YI => '乙', TG_BING => '丙', TG_DING => '丁', TG_WU => '戊',
        TG_JI => '己', TG_GENG => '庚', TG_XIN => '辛', TG_REN => '壬', TG_GUI => '癸'
    ];
    // 十二地支
    private $dizhi = [
        DZ_ZI => '子', DZ_CHOU => '丑', DZ_YIN => '寅', DZ_MAO => '卯', DZ_CHEN => '辰', DZ_SI => '巳',
        DZ_WU => '午', DZ_WEI => '未', DZ_SHEN => '申', DZ_YOU => '酉', DZ_XU => '戌', DZ_HAI => '亥'
    ];


    // 五行局
    private $wuxingju = [
        WX_JIN => '金四局',
        WX_MU => '木三局',
        WX_SHUI => '水二局',
        WX_HUO => '火六局',
        WX_TU => '土五局',
    ];

    // 五行局起始岁数
    private $wuxingQishi = [
        WX_JIN => 4,
        WX_MU => 3,
        WX_SHUI => 2,
        WX_HUO => 6,
        WX_TU => 5,
    ];
    // 开启真太阳时是否会导致八字信息发生改变，若发生改变则需要进行提示
    private $is_need_show_tip = 0;

    /**
     * 档案信息
     * @var array
     */
    protected $recordInfo = [
        'type' => 1,// 用户性别/类别 [1=>男,2=>女]
        'year' => 1995,// 出生日期-年
        'month' => 1,// 出生日期-月 1~12
        'day' => 1,// 出生日期-日 1~
        'hour' => 0,// 出生日期-小时 0~23
        'minute' => 0,// 出生日期-分钟 0~59
        'timezone' => 8,// 出生日期-时区 -12~12
        'birth_country' => '北京市',// 出生地址-省
        'birth_province' => '北京市',// 出生地址-市
        'birth_city' => '朝阳区',// 出生地址-区
        'live_country' => '北京市',// 现居地址-省
        'live_province' => '北京市',// 现居地址-市
        'live_city' => '朝阳区',// 现居地址-区
        'long_deg' => 116,// 出生地-经度-度 0~180
        'long_min' => 27,// 出生地-经度-分 0~59
        'ew' => 1,// -1=>西经,1=>东经
        'lat_deg' => 39,// 出生地-纬度-度 0~90
        'lat_min' => 56,// 出生地-纬度-分 0~59
        'ns' => 1,// -1=>南纬,1=>北纬
        'is_summer' => 0,// 是否为夏令时
    ];

    /**
     * 紫微设置
     * @var array
     */
    protected $setting = [
        'time_type' => 1,// 时间类型 [0=>北京时间,1=>真太阳时]
        'time_start' => 1,// 日辰初始 [0 => 24点,1=>子时]
        'zihua' => 1, // 飞星自化 0=>关闭, 1=>开启
        'sihua_jia' => 0, //    四化-甲   0=>廉破武阳, 1=>廉破曲阳
        'sihua_wu' => 0, //     四化-戊   0=>贪阴右机, 1=>贪阴阳机
        'sihua_geng' => 0, //   四化-庚   0=>阳武阴同, 1=>阳武府同
        'sihua_xin' => 0, //    四化-辛   0=>巨阳曲昌, 1=>巨阳武昌
        'sihua_ren' => 0, //    四化-壬   0=>梁紫左武, 1=>梁紫府武
        'sihua_gui' => 0, //    四化-癸   0=>破巨阴贪, 1=>破巨阳贪
        'runyue' => 0,// 闰月分界 0=>月中分隔, 1=>隶属本月, 2=>隶属下月
        'an_kuiyue' => 0, // 安魁钺星口诀  0=>六辛逢马虎, 1=>六辛逢虎马
    ];

    /**
     * 公共方法：设置档案信息 支持链式
     * @param array $param
     * @return $this
     */
    public function setRecordInfo(array $param = []): Ziwei
    {
        // 粗略检查档案信息是否齐全
        if (!empty($param) && isset($param['type'], $param['year'], $param['month'], $param['day'], $param['hour'], $param['minute'], $param['timezone'], $param['long_deg'], $param['long_min'], $param['ew'], $param['lat_deg'], $param['lat_min'], $param['ns'], $param['is_summer']))
        {
            $this->recordInfo = $param;
        }
        return $this;
    }

    /**
     * 设置参数
     * @param array $param
     * @return $this
     */
    public function setSetting(array $param = []): Ziwei
    {
        if (!empty($param))
        {
            if (isset($param['time_type']) && in_array($param['time_type'], [0, 1], false))
            {
                $this->setting['time_type'] = (int)$param['time_type'];
            }
            if (isset($param['time_start']) && in_array($param['time_start'], [0, 1], false))
            {
                $this->setting['time_start'] = (int)$param['time_start'];
            }
            if (isset($param['zihua']) && in_array($param['zihua'], [0, 1], false))
            {
                $this->setting['zihua'] = (int)$param['zihua'];
            }
            if (isset($param['sihua_jia']) && in_array($param['sihua_jia'], [0, 1], false))
            {
                $this->setting['sihua_jia'] = (int)$param['sihua_jia'];
            }
            if (isset($param['sihua_wu']) && in_array($param['sihua_wu'], [0, 1], false))
            {
                $this->setting['sihua_wu'] = (int)$param['sihua_wu'];
            }
            if (isset($param['sihua_geng']) && in_array($param['sihua_geng'], [0, 1], false))
            {
                $this->setting['sihua_geng'] = (int)$param['sihua_geng'];
            }
            if (isset($param['sihua_xin']) && in_array($param['sihua_xin'], [0, 1], false))
            {
                $this->setting['sihua_xin'] = (int)$param['sihua_xin'];
            }
            if (isset($param['sihua_ren']) && in_array($param['sihua_ren'], [0, 1], false))
            {
                $this->setting['sihua_ren'] = (int)$param['sihua_ren'];
            }
            if (isset($param['sihua_gui']) && in_array($param['sihua_gui'], [0, 1], false))
            {
                $this->setting['sihua_gui'] = (int)$param['sihua_gui'];
            }
            if (isset($param['runyue']) && in_array($param['runyue'], [0, 1, 2], false))
            {
                $this->setting['runyue'] = (int)$param['runyue'];
            }
            if (isset($param['an_kuiyue']) && in_array($param['an_kuiyue'], [0, 1], false))
            {
                $this->setting['an_kuiyue'] = (int)$param['an_kuiyue'];
            }
        }
        return $this;
    }

    /**
     * 获取紫微盘数据
     * @return array
     */
    public function getChartInfo(): array
    {
        $sex = (int)$this->recordInfo['type'];
        // 出生时间转换为时间戳
        $time = strtotime($this->recordInfo['year'] . '-' . $this->recordInfo['month'] . '-' . $this->recordInfo['day'] . ' ' . $this->recordInfo['hour'] . ':' . $this->recordInfo['minute']);
        // 获取命主太阳度数
        $sunDeg = Astrolog::getInstance()->setExecPrefix(config('astrolog.prefix'))->getPlanetOriginData('0', $this->recordInfo)[0] * 1;
        // 计算八字
        $bazi = $this->getBazi($time, $sunDeg);
        $ngs = array_search($bazi[1], $this->tiangan, true); // 出生年干索引
        $nzs = array_search($bazi[2], $this->dizhi, true); // 出生年支索引
        $szs = array_search($bazi[8], $this->dizhi, true); // 出生时支索引
        // 公历转换为农历
        $nongliData = (new Calendar())->solar($this->recordInfo['year'], $this->recordInfo['month'], $this->recordInfo['day']);
        $nongli = [
            'year' => $nongliData['lunar_year_chinese'],
            'month' => $nongliData['lunar_month_chinese'],
            'day' => $nongliData['lunar_day_chinese'],
        ];

        // 将农历日汉字转换为数字
        $nlr = $this->nongli2Num($nongli['day'], 1);
        // 将农历月汉字转换为数字
        $nly = $this->nongli2Num($nongli['month'], 0);
        // 若出生月份为闰月
        if (strpos($nongli['month'], '闰') !== false)
        {
            // 月中分隔
            if ($this->setting['runyue'] === 0)
            {
                if ($nlr > 15)
                {
                    $nly++;
                }
            }// 隶属下月
            elseif ($this->setting['runyue'] === 2)
            {
                $nly++;
            }
        }
        // 定命宫所在地支
        $mgz = $this->getMinggong($nly, $szs);
        // 定身宫所在地支
        $sgz = $this->getShengong($nly, $szs);
        // 定五行局  水二局、木三局、金四局、土五局、火六局 [0,4]按金木水火土顺序进行排序
        $wxj = $this->getWuxingJu($ngs, $mgz);
        // 定紫薇星所在宫位
        $zwg = $this->getZiweiGong($wxj, $nlr);

        $option = [
            'zwg' => $zwg,
            'wxj' => $wxj,
            'ngs' => $ngs,
            'nzs' => $nzs,
            'szs' => $szs,
            'nly' => $nly,
            'nlr' => $nlr,
            'mgz' => $mgz,
            'sgz' => $sgz,
        ];

        $xing = [];
        for ($i = 0; $i <= 68; $i++)
        {
            $xing[$i] = $this->getXingyao($i, $option);
        }
        // 命主：贪狼、巨门、禄存、文曲、廉贞、武曲、破军
        $mingzhu = $this->getMingzhu($mgz);
        // 身主：铃、天相、天梁、天同、文昌、天机、火
        $shenzhu = $this->getShenzhu($nzs);
        // 安四化星 化禄星、化权星、化科星、化忌星
        $shengnianSihua = $this->getSihua($ngs);

        $liuri = $this->getLiuri(time());

        $liunianganzhi = current($liuri)['liunian'];
        $liuzhi = array_search($liunianganzhi[1], $this->dizhi, true);

        $data = [
            'rid' => $this->recordInfo['id'],
            'gong' => [],
            'info' => [
                'name' => $this->recordInfo['name'],
                'yinyang' => $this->getYinyangText($ngs % 2) . ($sex === 1 ? '男' : '女'), // 阳男｜阴男｜阳女｜阴女
                'wuxingju' => $this->wuxingju[$wxj], // 五行局
                'shijian0' => [],
                'shijian' => [
                    'name' => $this->setting['time_type'] === 0 ? '北京时间' : '真太阳时',
                    'value' => $this->recordInfo['real_time']
                ], // 真太阳时
                'nongli' => [
                    'name' => '农历',
                    'value' => $bazi[1] . $bazi[2] . '年' . $nongliData['lunar_month_chinese'] . $nongliData['lunar_day_chinese'] . '日 ' . $bazi[8] . '时'
                ], // 农历 例如：戊寅年五月廿六日 巳时
                'mingzhu' => [
                    'name' => '命主',
                    'value' => $this->getXingText($mingzhu),
                ],
                'shenzhu' => [
                    'name' => '身主',
                    'value' => $this->getXingText($shenzhu),
                ],
                'ziniandoujun' => [
                    'name' => '子斗',
                    'value' => $this->getDizhiText($this->getZinianDoujun($nly, $szs)),
                ],
                'liuniandoujun' => [
                    'name' => '流斗',
                    'value' => $this->getDizhiText($this->getLiunianDoujun($nly, $szs, $liuzhi)), // 获取流年地支，然后传值
                ],
            ],
            'setting' => $this->setting, // 紫微相关设置
            'is_need_show_tip' => $this->is_need_show_tip,
        ];

        if ($this->setting['time_type'] === 1)
        {
            $data['info']['shijian0'] = [
                'name' => '北京时间',
//                'value' => $this->recordInfo['year'] . '.' . $this->recordInfo['month'] . '.' . $this->recordInfo['day'] . ' ' . $this->recordInfo['hour'] . '.' . $this->recordInfo['minute'],
                'value' => date('Y.m.d H:i', $time),
            ];
        }

        // 获取起运年龄
        $qiyunNianling = $this->wuxingQishi[$wxj] ?? 1;
        $suishu = $this->getSuishu($time, time());

        foreach ($this->dizhi as $k1 => $v1)
        {
            // 安12宫天干
            $gg = $this->getGonggan($ngs, $k1);
            // 获取12宫索引
            $index1 = $this->resetIndex($mgz - $k1);
            // 大限：阳男阴女由命宫顺行,阴男阳女由命宫逆行,岁数的起法以五行局为准
            if ($data['info']['yinyang'] === '阳男' || $data['info']['yinyang'] === '阴女')
            {
                $kaishiSui = $this->resetIndex($k1 - $mgz) * 10 + $qiyunNianling;
                $shixianzai = 0;
                // 此处计算虚岁年龄，如果满周岁那么当前年龄+1
                if ($suishu >= $kaishiSui && $suishu <= $kaishiSui + 9)
                {
                    $shixianzai = 1;
                }
            } else
            {
                $kaishiSui = $index1 * 10 + $qiyunNianling;
                $shixianzai = 0;
                // 此处计算虚岁年龄，如果满周岁那么当前年龄+1
                if ($suishu >= $kaishiSui && $suishu <= $kaishiSui + 9)
                {
                    $shixianzai = 1;
                }
            }
            // 小限：男顺，女逆。 歌诀：寅午戌人起辰宫，申子辰人起戌宫，巳酉丑人起未宫，亥卯未人起丑宫。
            $xiaoxian = $this->getXiaoxian($nzs);
            if ($sex === 1)
            {
                $index2 = $this->resetIndex($k1 - $xiaoxian);
            } else
            {
                $index2 = $this->resetIndex($xiaoxian - $k1);
            }
            $nian = $index2 + 1;
            // 初始化年份字符串
            $nianStr = $nian;
            for ($i = 1; $i < 6; $i++)
            {
                // 逗号拼接剩下的年份
                $nianStr .= ',' . ($nian + $i * 12);
            }

            // 计算宫干四化
            $gongSihua = $this->getSihua($gg);
            // 计算对宫宫干四化
            $duigongIndex = $this->resetIndex($k1 + 6);
            $dgg = $this->getGonggan($ngs, $duigongIndex);
            $duigongSihua = $this->getSihua($dgg);

            $zaigongXing = array_keys($xing, $k1); // 获取所有在该宫位的星
            $gongzhongxing = [];
            foreach ($zaigongXing as $k2 => $v2)
            {
                $tmp = [];
                $tmp['id'] = $v2; // 星耀ID
                // 名字
                $tmp['name'] = $this->getXingText($v2);
                // 该星的颜色
                $tmp['type'] = ''; // 初始化
                if ($v2 <= 13)
                {
                    // 14主星
                    $tmp['type'] = 'zhu';
                } elseif ($v2 <= 21)
                {
                    // 8吉星
                    $tmp['type'] = 'jixing';
                } elseif ($v2 <= 27)
                {
                    // 6煞星
                    $tmp['type'] = 'xiongxing';
                }
                // 状态 该星的得分（庙旺）
                $tmp['zhuangtai'] = $this->getDefenText2($this->getDefen2($v2, $k1));
                // 判断是否为生年四化
                if ($v2 === $shengnianSihua[SH_LU])
                {
                    $tmp['shengnian_sihua'] = '禄';
                } elseif ($v2 === $shengnianSihua[SH_QUAN])
                {
                    $tmp['shengnian_sihua'] = '权';
                } elseif ($v2 === $shengnianSihua[SH_KE])
                {
                    $tmp['shengnian_sihua'] = '科';
                } elseif ($v2 === $shengnianSihua[SH_JI])
                {
                    $tmp['shengnian_sihua'] = '忌';
                } else
                {
                    $tmp['shengnian_sihua'] = '';
                }

                $tmp['zihua_lu'] = 0;
                $tmp['zihua_quan'] = 0;
                $tmp['zihua_ke'] = 0;
                $tmp['zihua_ji'] = 0;
                $tmp['huadui_lu'] = 0;
                $tmp['huadui_quan'] = 0;
                $tmp['huadui_ke'] = 0;
                $tmp['huadui_ji'] = 0;
                if ($this->setting['zihua'] === 1)
                {
                    // 判断是否为自化
                    if ($gongSihua[SH_LU] === $v2 && $xing[$gongSihua[SH_LU]] === $k1)
                    {
                        // 宫干化禄在本宫
                        $tmp['zihua_lu'] = 1;
                    }
                    if ($gongSihua[SH_QUAN] === $v2 && $xing[$gongSihua[SH_QUAN]] === $k1)
                    {
                        // 宫干化权在本宫
                        $tmp['zihua_quan'] = 1;
                    }
                    if ($gongSihua[SH_KE] === $v2 && $xing[$gongSihua[SH_KE]] === $k1)
                    {
                        // 宫干化科在本宫
                        $tmp['zihua_ke'] = 1;
                    }
                    if ($gongSihua[SH_JI] === $v2 && $xing[$gongSihua[SH_JI]] === $k1)
                    {
                        // 宫干化忌在本宫
                        $tmp['zihua_ji'] = 1;
                    }

                    // 判断是否为对宫化入
                    if ($duigongSihua[SH_LU] === $v2 && $xing[$duigongSihua[SH_LU]] === $k1)
                    {
                        // 宫干化禄在本宫
                        $tmp['huadui_lu'] = 1;
                    }
                    if ($duigongSihua[SH_QUAN] === $v2 && $xing[$duigongSihua[SH_QUAN]] === $k1)
                    {
                        // 宫干化权在本宫
                        $tmp['huadui_quan'] = 1;
                    }
                    if ($duigongSihua[SH_KE] === $v2 && $xing[$duigongSihua[SH_KE]] === $k1)
                    {
                        // 宫干化科在本宫
                        $tmp['huadui_ke'] = 1;
                    }
                    if ($duigongSihua[SH_JI] === $v2 && $xing[$duigongSihua[SH_JI]] === $k1)
                    {
                        // 宫干化忌在本宫
                        $tmp['huadui_ji'] = 1;
                    }
                }

                $gongzhongxing[] = $tmp;
            }
            // 以命宫所在地支为0，按照 逆时针 排12宫位
            $data['gong'][] = [
                'gan' => $this->getTianganText($gg), // 宫干
                'zhi' => $v1, // 宫支
                'mingcheng' => $this->houseList[$index1], // 宫位名称
                'boshi' => $this->getBoshiText($this->getBoshi($xing[ZW_LUCUN], $k1, $data['info']['yinyang'])),
                'changsheng' => $this->getChangshengText($this->getChangsheng($wxj, $k1, $data['info']['yinyang'])), // 长生
                'jiangqian' => $this->getJiangqianText($this->getJiangqian($nzs, $k1)), // 将前
                'taisui' => $this->getTaisuiText($this->getTaisui($nzs, $k1)), // 太岁
                'xing' => $gongzhongxing,
                'xingshu' => count($gongzhongxing),
                'nian' => $nianStr, // 年 例如：2,14,26,38,50,62
                'nianlingduan' => $kaishiSui . '-' . ($kaishiSui + 9), // 掌管的年龄段 例如：22-31
                'shiminggong' => ($k1 === $mgz ? 1 : 0), // 是否为命宫
                'shishengong' => ($k1 === $sgz ? 1 : 0), // 是否为身宫
                'shixianzai' => $shixianzai, // 年龄是否在当前年龄段
                'hualu' => $gongSihua[SH_LU],
                'huaquan' => $gongSihua[SH_QUAN],
                'huake' => $gongSihua[SH_KE],
                'huaji' => $gongSihua[SH_JI],
            ];
        }

        return $data;
    }

    public function getChartDetail(): array
    {
        $sex = (int)$this->recordInfo['type'];
        // 出生时间转换为时间戳
        $time = strtotime($this->recordInfo['year'] . '-' . $this->recordInfo['month'] . '-' . $this->recordInfo['day'] . ' ' . $this->recordInfo['hour'] . ':' . $this->recordInfo['minute']);
        // 获取命主太阳度数
        $sunDeg = Astrolog::getInstance()->setExecPrefix(config('astrolog.prefix'))->getPlanetOriginData('0', $this->recordInfo)[0] * 1;
        // 计算八字
        $bazi = $this->getBazi($time, $sunDeg);
        $ngs = array_search($bazi[1], $this->tiangan, true); // 出生年干索引
        $nzs = array_search($bazi[2], $this->dizhi, true); // 出生年支索引
        $szs = array_search($bazi[8], $this->dizhi, true); // 出生时支索引
        // 公历转换为农历
        $nongliData = (new Calendar())->solar($this->recordInfo['year'], $this->recordInfo['month'], $this->recordInfo['day']);
        $nongli = [
            'year' => $nongliData['lunar_year_chinese'],
            'month' => $nongliData['lunar_month_chinese'],
            'day' => $nongliData['lunar_day_chinese'],
        ];

        // 将农历日汉字转换为数字
        $nlr = $this->nongli2Num($nongli['day'], 1);
        // 将农历月汉字转换为数字
        $nly = $this->nongli2Num($nongli['month'], 0);
        // 若出生月份为闰月
        if (strpos($nongli['month'], '闰', true) !== false)
        {
            // 月中分隔
            if ($this->setting['runyue'] === 0)
            {
                if ($nlr > 15)
                {
                    $nly++;
                }
            }// 隶属下月
            elseif ($this->setting['runyue'] === 2)
            {
                $nly++;
            }
        }
        // 定命宫所在地支
        $mgz = $this->getMinggong($nly, $szs);
        // 定身宫所在地支
        $sgz = $this->getShengong($nly, $szs);
        // 定五行局  水二局、木三局、金四局、土五局、火六局 [0,4]按金木水火土顺序进行排序
        $wxj = $this->getWuxingJu($ngs, $mgz);
        // 定紫薇星所在宫位
        $zwg = $this->getZiweiGong($wxj, $nlr);
        // 安生年四化星 化禄星、化权星、化科星、化忌星
        $shengnianSihua = $this->getSihua($ngs);

        $data = [
            'xing' => [],
            'gong' => [],
        ];

        for ($j = ZW_H1; $j <= ZW_H12; $j++)
        {
            $z = $this->resetIndex($mgz + $j);
            $gongTmp = [
                'name' => $this->houseList[$j],
                'xing_list' => [],
                'dizhi_num' => $z,
                'dizhi_text' => $this->getDizhiText($z)
            ];
            $data['gong'][$j] = $gongTmp;
        }

        $option = [
            'zwg' => $zwg,
            'wxj' => $wxj,
            'ngs' => $ngs,
            'nzs' => $nzs,
            'szs' => $szs,
            'nly' => $nly,
            'nlr' => $nlr,
            'mgz' => $mgz,
            'sgz' => $sgz,
        ];
        for ($i = 0; $i <= 27; $i++)
        {
            $dz = $this->getXingyao($i, $option);
            $gong = $this->resetIndex($mgz - $dz);
            // 安天干
            $gg = $this->getGonggan($ngs, $dz);
            $xingTmp = [
                'name' => $this->getXingText($i),
                'gong_num' => $gong,
                'gong_text' => $this->houseList[$gong],
                'gan_num' => $gg,
                'gan_text' => $this->tiangan[$gg],
                'dizhi_num' => $dz,
                'dizhi_text' => $this->getDizhiText($dz),
                'shuxing' => $this->getXingShuxingText($this->getXingShuxing($i, $dz)),
                'sihua' => '',
                'zhuangtai' => $this->getDefenText2($this->getDefen2($i, $dz)),
            ];
            // 判断是否为生年四化
            if ($i === $shengnianSihua[SH_LU])
            {
                $xingTmp['sihua'] = '禄';
            } elseif ($i === $shengnianSihua[SH_QUAN])
            {
                $xingTmp['sihua'] = '权';
            } elseif ($i === $shengnianSihua[SH_KE])
            {
                $xingTmp['sihua'] = '科';
            } elseif ($i === $shengnianSihua[SH_JI])
            {
                $xingTmp['sihua'] = '忌';
            }
            $data['gong'][$gong]['xing_list'][] = $xingTmp['name'];
            $data['xing'][] = $xingTmp;
        }

        return $data;
    }

    /**
     * 获取八字
     * @param $time
     * @param int $sunDeg
     * @param bool $getHour
     * @return array
     */
    public function getBazi($time, $sunDeg = 0, $getHour = true): array
    {
        // 十天干
        $tiangan = $this->tiangan;
        // 十二地支
        $Earthly_Branches = $this->dizhi;
        // 六十甲子
        $liushijiazi = [
            0 => '甲子',
            1 => '乙丑',
            2 => '丙寅',
            3 => '丁卯',
            4 => '戊辰',
            5 => '己巳',
            6 => '庚午',
            7 => '辛未',
            8 => '壬申',
            9 => '癸酉',
            10 => '甲戌',
            11 => '乙亥',
            12 => '丙子',
            13 => '丁丑',
            14 => '戊寅',
            15 => '己卯',
            16 => '庚辰',
            17 => '辛巳',
            18 => '壬午',
            19 => '癸未',
            20 => '甲申',
            21 => '乙酉',
            22 => '丙戌',
            23 => '丁亥',
            24 => '戊子',
            25 => '己丑',
            26 => '庚寅',
            27 => '辛卯',
            28 => '壬辰',
            29 => '癸巳',
            30 => '甲午',
            31 => '乙未',
            32 => '丙申',
            33 => '丁酉',
            34 => '戊戌',
            35 => '己亥',
            36 => '庚子',
            37 => '辛丑',
            38 => '壬寅',
            39 => '癸卯',
            40 => '甲辰',
            41 => '乙巳',
            42 => '丙午',
            43 => '丁未',
            44 => '戊申',
            45 => '己酉',
            46 => '庚戌',
            47 => '辛亥',
            48 => '壬子',
            49 => '癸丑',
            50 => '甲寅',
            51 => '乙卯',
            52 => '丙辰',
            53 => '丁巳',
            54 => '戊午',
            55 => '己未',
            56 => '庚申',
            57 => '辛酉',
            58 => '壬戌',
            59 => '癸亥',
        ];

        // 增加夏令时计算
        if ($this->recordInfo['is_summer'] == 1)
        {
            $time -= 3600;
        }

        // 若为真太阳时则(目前只计算了平太阳时)
        if ($this->setting['time_type'] == 1)
        {
            $yy = (int)date('Y', $time);
            $mm = (int)date('m', $time);
            $dd = (int)date('d', $time);
            $hh = (int)date('H', $time);
            $ii = (int)date('i', $time);
            $longitude = ($this->recordInfo['long_deg'] + $this->recordInfo['long_min'] / 60) * $this->recordInfo['ew'];
            $latitude = ($this->recordInfo['lat_deg'] + $this->recordInfo['lat_min'] / 60) * $this->recordInfo['ns'];
            $zty = (new Util())->zhenTaiyangShi($yy, $mm, $dd, $hh, $ii, 0, $longitude, $latitude);
            $time = $time + ($longitude - $this->recordInfo['timezone'] * 15) * 4 * 60;
            try
            {
                $this->recordInfo['real_time'] = $zty[0] . '.' . str_pad($zty[1], 2, '0', STR_PAD_LEFT) . '.' . str_pad($zty[2], 2, '0', STR_PAD_LEFT) . ' ' . str_pad($zty[3], 2, '0', STR_PAD_LEFT) . '.' . str_pad($zty[4], 2, '0', STR_PAD_LEFT);
                $shichen = [
                    DZ_CHOU => [1, 3],
                    DZ_YIN => [3, 5],
                    DZ_MAO => [5, 7],
                    DZ_CHEN => [7, 9],
                    DZ_SI => [9, 11],
                    DZ_WU => [11, 13],
                    DZ_WEI => [13, 15],
                    DZ_SHEN => [15, 17],
                    DZ_YOU => [17, 19],
                    DZ_XU => [19, 21],
                    DZ_HAI => [21, 23],
                ];
                $bjsj = 0;
                $ztysj = 0;
                foreach ($shichen as $k => $v)
                {
                    if ($hh >= $v[0] && $hh < $v[1])
                    {
                        $bjsj = $k;
                    }
                    if ($zty[3] >= $v[0] && $zty[3] < $v[1])
                    {
                        $ztysj = $k;
                    }
                }
                // 判断是否需要提示真太阳时对生辰信息产生了影响
                if ($bjsj !== $ztysj)
                {
                    $this->is_need_show_tip = 1;
                }
            }
            catch (Exception $e)
            {
                Log::write('紫微真太阳时处理失败:' . $e->getMessage() . ' [' . $e->getFile() . ':' . $e->getLine() . ']');
                // 平太阳时
                $time += (8 - $this->recordInfo['timezone']) * 3600;
                $this->recordInfo['real_time'] = date('Y.m.d H:i', $time);
            }
        }// 默认使用北京时间 把用户时间转换成北京时间
        else
        {
            $time += (8 - $this->recordInfo['timezone']) * 3600;
            $this->recordInfo['real_time'] = date('Y.m.d H:i', $time);
        }

        $year = date('Y', $time) * 1;
        $month = date('m', $time) * 1;
        $hour = (int)(date('H', $time));

        $nianganzhi = $this->getNianganzhi($year);

        if ($month < 3 && $sunDeg < 315)
        {
            $nianganzhi--;

            if ($nianganzhi < 0) $nianganzhi = 59;
        }

        $bazi_str = $liushijiazi[$nianganzhi];
        // 每15度一个节气   总共二十四节气  月令地支
        $month_branche = ["卯", "辰", "辰", "巳", "巳", "午", "午", "未", "未", "申", "申", "酉", "酉", "戌", "戌", "亥", "亥", "子", "子", "丑", "丑", "寅", "寅", "卯"];

        $temp = ["寅", "卯", "辰", "巳", "午", "未", "申", "酉", "戌", "亥", "子", "丑"];// 十二个月

        // $temp2 = ["丙","戊","庚","壬","甲","丙","戊","庚","壬","甲"];
        $temp2 = [2, 4, 6, 8, 0, 2, 4, 6, 8, 0];

        $month_branche_num = (int)(floor($sunDeg / 15));// 向下取整

        $month_branche_str = $month_branche[$month_branche_num];// 月令地支

        $year_stem = mb_substr($bazi_str, 0, 1, 'utf-8');

        $year_num = array_search($year_stem, $tiangan);

        $start_num = $temp2[$year_num];

        $month_branche_num = array_search($month_branche_str, $temp);

        $newArr = array_merge($tiangan, $tiangan, $tiangan);

        $s = [];

        for ($i = $start_num; $i < $start_num + 12; $i++) $s[] = $newArr[$i];

        $month_stem_branche = $s[$month_branche_num] . $month_branche_str;

        $time2 = 941990400;

        $time1 = strtotime(date('Y-m-d', $time));
        // 日辰初始默认使用24点
        $val = ($time1 - $time2) / 3600 / 24 % 60;

        // 日辰初始使用23点
        if ($getHour && $this->setting['time_start'] == 1 && $hour == 23)
        {
            $val++;
            if ($val == 60) $val = 0;
        }

        $day_stem_branche = $val < 0 ? $val + 60 : $val;

        $bazi_str .= $month_stem_branche;

        $bazi_str .= $liushijiazi[$day_stem_branche];

        $bazi = [
            1 => mb_substr($bazi_str, 0, 1, 'utf8'),
            2 => mb_substr($bazi_str, 1, 1, 'utf8'),
            3 => mb_substr($bazi_str, 2, 1, 'utf8'),
            4 => mb_substr($bazi_str, 3, 1, 'utf8'),
            5 => mb_substr($bazi_str, 4, 1, 'utf8'),
            6 => mb_substr($bazi_str, 5, 1, 'utf8'),
        ];

        if ($getHour)
        {
            // 二十四小时，十二个时辰  时辰地支
            $hour_branche = ["子", "丑", "丑", "寅", "寅", "卯", "卯", "辰", "辰", "巳", "巳", "午", "午", "未", "未", "申", "申", "酉", "酉", "戌", "戌", "亥", "亥", "子"];

            // $temp2 = ["甲","丙","戊","庚","壬","甲","丙","戊","庚","壬"];
            $temp2 = [0, 2, 4, 6, 8, 0, 2, 4, 6, 8];

            $hour_branche_str = $hour_branche[$hour];// 时辰地支

            $day_stem_branche = mb_substr($liushijiazi[$day_stem_branche], 0, 1, 'utf-8');

            $day_num = array_search($day_stem_branche, $tiangan);

            // 若日辰初始为24点，且为晚子时（23～0点之间，包含0点），则晚子时的人往下推一天
            if ($this->setting['time_start'] != 1 && $hour == 23)
            {
                $day_num++;
                // 溢出处理
                if ($day_num === 10)
                {
                    $day_num = 0;
                }
            }
            $start_num = $temp2[$day_num];

            $hour_branche_num = array_search($hour_branche_str, $Earthly_Branches);

            $newArr = array_merge($tiangan, $tiangan, $tiangan);

            $s = [];
            for ($i = $start_num; $i < $start_num + 12; $i++)
            {
                $s[] = $newArr[$i];
            }

            $bazi_str .= $s[$hour_branche_num] . $hour_branche_str;

            $bazi[7] = mb_substr($bazi_str, 6, 1, 'utf8');
            $bazi[8] = mb_substr($bazi_str, 7, 1, 'utf8');
        }

        return $bazi;
    }

    /**
     * 获取指定日期流日、流月、流年
     * @param int $time 指定日期时间戳
     * @param int $num 需要获取连续多少天的流日
     * @return array
     */
    public function getLiuri(int $time = 0, int $num = 1): array
    {
        // 六十甲子
        $liushijiazi = [
            0 => '甲子',
            1 => '乙丑',
            2 => '丙寅',
            3 => '丁卯',
            4 => '戊辰',
            5 => '己巳',
            6 => '庚午',
            7 => '辛未',
            8 => '壬申',
            9 => '癸酉',
            10 => '甲戌',
            11 => '乙亥',
            12 => '丙子',
            13 => '丁丑',
            14 => '戊寅',
            15 => '己卯',
            16 => '庚辰',
            17 => '辛巳',
            18 => '壬午',
            19 => '癸未',
            20 => '甲申',
            21 => '乙酉',
            22 => '丙戌',
            23 => '丁亥',
            24 => '戊子',
            25 => '己丑',
            26 => '庚寅',
            27 => '辛卯',
            28 => '壬辰',
            29 => '癸巳',
            30 => '甲午',
            31 => '乙未',
            32 => '丙申',
            33 => '丁酉',
            34 => '戊戌',
            35 => '己亥',
            36 => '庚子',
            37 => '辛丑',
            38 => '壬寅',
            39 => '癸卯',
            40 => '甲辰',
            41 => '乙巳',
            42 => '丙午',
            43 => '丁未',
            44 => '戊申',
            45 => '己酉',
            46 => '庚戌',
            47 => '辛亥',
            48 => '壬子',
            49 => '癸丑',
            50 => '甲寅',
            51 => '乙卯',
            52 => '丙辰',
            53 => '丁巳',
            54 => '戊午',
            55 => '己未',
            56 => '庚申',
            57 => '辛酉',
            58 => '壬戌',
            59 => '癸亥',
        ];

        $res = [];

        $time2 = 941990400;

        $time1 = strtotime(date('Y-m-d', $time));
        // 日辰初始默认使用24点
        $val = ($time1 - $time2) / 86400 % 60;
        // 处理流日索引在0～60之间
        $dayIndex = $val < 0 ? $val + 60 : $val;

        $advanceInfo = [
            'year' => (int)date('Y', $time1),
            'month' => (int)date('n', $time1),
            'day' => (int)date('d', $time1),
            'hour' => (int)date('H', $time1),
            'minute' => (int)date('i', $time1),
            'timezone' => 8,
            'is_summer' => 0,
        ];

        $liunianIndex = $this->getNianganzhi($advanceInfo['year']);

        // 获取开始时间的太阳度数
        $sunDeg = (Astrolog::getInstance())->setExecPrefix(config('astrolog.prefix'))->getPlanetOriginData('0', $advanceInfo)[0] * 1;

        // 获取连续N天的流日
        for ($i = 0; $i < $num; $i++)
        {
            if ($dayIndex === 60)
            {
                $dayIndex -= 60;
            }
            // 流日干支字符串
            $rizhuString = $liushijiazi[$dayIndex];
            // 流日时间戳
            $dayTime = $time + 86400 * $i;
            // 所属月份
            $month = (int)date('n', $dayTime);
            // 流日干支数组
            $liuri = [mb_substr($rizhuString, 0, 1), mb_substr($rizhuString, 1, 1)];
            // 当前流日太阳度数
            $cSunDeg = $sunDeg + $i;
            if ($cSunDeg >= 360)
            {
                $cSunDeg = mod360($cSunDeg);
            }
            $nianIndex = $liunianIndex;
            if ($month < 3 && $cSunDeg < 315)
            {
                // 未立春显示上一年干支
                $nianIndex--;
            }
            if ($nianIndex < 0) $nianIndex = 59;
            // 流年 干支
            $liunianString = $liushijiazi[$nianIndex];
            // 流年干支数组
            $liunian = [mb_substr($liunianString, 0, 1), mb_substr($liunianString, 1, 1)];
            $liuyue = $this->getLiuyueGanzhi($liunian[0], $sunDeg);
            // 日期字符串
            $date = date('Y-m-d', $dayTime);
            $res[$date] = [
                'liuri' => $liuri,
                'liuyue' => $liuyue,
                'liunian' => $liunian
            ];
            $dayIndex++;
        }
        return $res;
    }

    /**
     * 计算流月天干地支(年干取月)
     * @param string $nianGan 年干
     * @param int $sunDeg 太阳度数
     * @return array
     */
    protected function getLiuyueGanzhi(string $nianGan = '', int $sunDeg = 0): array
    {
        $res = [];
        // 每15度一个节气   总共二十四节气  月令地支
        $month_branche = ['卯', '辰', '辰', '巳', '巳', '午', '午', '未', '未', '申', '申', '酉', '酉', '戌', '戌', '亥', '亥', '子', '子', '丑', '丑', '寅', '寅', '卯'];

        $temp = ['寅', '卯', '辰', '巳', '午', '未', '申', '酉', '戌', '亥', '子', '丑'];// 十二个月

        // $temp2 = ["丙","戊","庚","壬","甲","丙","戊","庚","壬","甲"];
        $temp2 = [2, 4, 6, 8, 0, 2, 4, 6, 8, 0];

        $month_branche_num = (int)(floor($sunDeg / 15));// 向下取整

        $month_branche_str = $month_branche[$month_branche_num];// 月令地支

        $year_num = array_search($nianGan, $this->tiangan, true);

        $start_num = $temp2[$year_num];

        $month_branche_num = array_search($month_branche_str, $temp);

        $newArr = array_merge($this->tiangan, $this->tiangan, $this->tiangan);

        $s = [];

        for ($i = $start_num; $i < $start_num + 12; $i++) $s[] = $newArr[$i];

        $res[0] = $s[$month_branche_num];
        $res[1] = $month_branche_str;
        return $res;
    }

    /**
     * 获取年龄
     * @param int $birth 出生时间戳
     * @param int $now 当前时间戳
     * @return int
     */
    protected function getSuishu(int $birth, int $now): int
    {
        $y1 = (int)date('Y', $birth);
        $y2 = (int)date('Y', $now);

        $md1 = (int)date('md', $birth);
        $md2 = (int)date('md', $now);

        $res = $y2 - $y1;
        // 计算虚岁，如果满周岁则虚岁需+1
        if ($md2 >= $md1)
        {
            $res++;
        }
        return $res;
    }

    /**
     * 获取年干支
     * @param int $year
     * @return int
     */
    protected function getNianganzhi(int $year): int
    {
        return ($year - 4) % 60 < 0 ? ($year - 4) % 60 + 60 : ($year - 4) % 60;
    }

    /**
     * 农历月日转数字
     * @param string $str 正月｜闰三月｜廿八
     * @param int $type 0=>月,1=>日
     * @return int
     */
    protected function nongli2Num(string $str = '', int $type = 1): int
    {
        $month = [null, '正', '二', '三', '四', '五', '六', '七', '八', '九', '十', '冬', '腊'];
        $day = [null, '初一', '初二', '初三', '初四', '初五', '初六', '初七', '初八', '初九', '初十', '十一', '十二', '十三', '十四', '十五', '十六', '十七', '十八', '十九', '二十', '廿一', '廿二', '廿三', '廿四', '廿五', '廿六', '廿七', '廿八', '廿九', '三十'];
        $res = 0;
        switch ($type)
        {
            case 0:
                $str = ltrim($str, '闰');
                $str = rtrim($str, '月');
                if (in_array($str, $month, true))
                {
                    $res = array_search($str, $month, true);
                    break;
                }
                break;
            default:
                $res = array_search($str, $day, true);
                break;
        }
        if ($res === false)
        {
            $res = 0;
        }
        return $res;
    }

    /**
     * 获取12宫天干
     * @param int $ng 年干
     * @param int $gz 宫支
     * @return int
     */
    protected function getGonggan(int $ng, int $gz): int
    {
        $config = [
            // 年干 => 宫支 => 宫干
            TG_JIA => [
                DZ_YIN => TG_BING,
                DZ_MAO => TG_DING,
                DZ_CHEN => TG_WU,
                DZ_SI => TG_JI,
                DZ_WU => TG_GENG,
                DZ_WEI => TG_XIN,
                DZ_SHEN => TG_REN,
                DZ_YOU => TG_GUI,
                DZ_XU => TG_JIA,
                DZ_HAI => TG_YI,
                DZ_ZI => TG_BING,
                DZ_CHOU => TG_DING,
            ],
            TG_YI => [
                DZ_YIN => TG_WU,
                DZ_MAO => TG_JI,
                DZ_CHEN => TG_GENG,
                DZ_SI => TG_XIN,
                DZ_WU => TG_REN,
                DZ_WEI => TG_GUI,
                DZ_SHEN => TG_JIA,
                DZ_YOU => TG_YI,
                DZ_XU => TG_BING,
                DZ_HAI => TG_DING,
                DZ_ZI => TG_WU,
                DZ_CHOU => TG_JI,
            ],
            TG_BING => [
                DZ_YIN => TG_GENG,
                DZ_MAO => TG_XIN,
                DZ_CHEN => TG_REN,
                DZ_SI => TG_GUI,
                DZ_WU => TG_JIA,
                DZ_WEI => TG_YI,
                DZ_SHEN => TG_BING,
                DZ_YOU => TG_DING,
                DZ_XU => TG_WU,
                DZ_HAI => TG_JI,
                DZ_ZI => TG_GENG,
                DZ_CHOU => TG_XIN,
            ],
            TG_DING => [
                DZ_YIN => TG_REN,
                DZ_MAO => TG_GUI,
                DZ_CHEN => TG_JIA,
                DZ_SI => TG_YI,
                DZ_WU => TG_BING,
                DZ_WEI => TG_DING,
                DZ_SHEN => TG_WU,
                DZ_YOU => TG_JI,
                DZ_XU => TG_GENG,
                DZ_HAI => TG_XIN,
                DZ_ZI => TG_REN,
                DZ_CHOU => TG_GUI,
            ],
            TG_WU => [
                DZ_YIN => TG_JIA,
                DZ_MAO => TG_YI,
                DZ_CHEN => TG_BING,
                DZ_SI => TG_DING,
                DZ_WU => TG_WU,
                DZ_WEI => TG_JI,
                DZ_SHEN => TG_GENG,
                DZ_YOU => TG_XIN,
                DZ_XU => TG_REN,
                DZ_HAI => TG_GUI,
                DZ_ZI => TG_JIA,
                DZ_CHOU => TG_YI,
            ],
            TG_JI => [
                DZ_YIN => TG_BING,
                DZ_MAO => TG_DING,
                DZ_CHEN => TG_WU,
                DZ_SI => TG_JI,
                DZ_WU => TG_GENG,
                DZ_WEI => TG_XIN,
                DZ_SHEN => TG_REN,
                DZ_YOU => TG_GUI,
                DZ_XU => TG_JIA,
                DZ_HAI => TG_YI,
                DZ_ZI => TG_BING,
                DZ_CHOU => TG_DING,
            ],
            TG_GENG => [
                DZ_YIN => TG_WU,
                DZ_MAO => TG_JI,
                DZ_CHEN => TG_GENG,
                DZ_SI => TG_XIN,
                DZ_WU => TG_REN,
                DZ_WEI => TG_GUI,
                DZ_SHEN => TG_JIA,
                DZ_YOU => TG_YI,
                DZ_XU => TG_BING,
                DZ_HAI => TG_DING,
                DZ_ZI => TG_WU,
                DZ_CHOU => TG_JI,
            ],
            TG_XIN => [
                DZ_YIN => TG_GENG,
                DZ_MAO => TG_XIN,
                DZ_CHEN => TG_REN,
                DZ_SI => TG_GUI,
                DZ_WU => TG_JIA,
                DZ_WEI => TG_YI,
                DZ_SHEN => TG_BING,
                DZ_YOU => TG_DING,
                DZ_XU => TG_WU,
                DZ_HAI => TG_JI,
                DZ_ZI => TG_GENG,
                DZ_CHOU => TG_XIN,
            ],
            TG_REN => [
                DZ_YIN => TG_REN,
                DZ_MAO => TG_GUI,
                DZ_CHEN => TG_JIA,
                DZ_SI => TG_YI,
                DZ_WU => TG_BING,
                DZ_WEI => TG_DING,
                DZ_SHEN => TG_WU,
                DZ_YOU => TG_JI,
                DZ_XU => TG_GENG,
                DZ_HAI => TG_XIN,
                DZ_ZI => TG_REN,
                DZ_CHOU => TG_GUI,
            ],
            TG_GUI => [
                DZ_YIN => TG_JIA,
                DZ_MAO => TG_YI,
                DZ_CHEN => TG_BING,
                DZ_SI => TG_DING,
                DZ_WU => TG_WU,
                DZ_WEI => TG_JI,
                DZ_SHEN => TG_GENG,
                DZ_YOU => TG_XIN,
                DZ_XU => TG_REN,
                DZ_HAI => TG_GUI,
                DZ_ZI => TG_JIA,
                DZ_CHOU => TG_YI,
            ],
        ];
        return $config[$ng][$gz];
    }

    /**
     * 获取命宫位置
     *  从寅宫起正月，顺时针方向数到出生月之宫止，再从该宫起子时，逆时针方向数到出生时支安命宫
     * @param int $nly 农历出生月
     * @param int $sz 出生时支
     * @return int
     */
    protected function getMinggong(int $nly, int $sz): int
    {
        $config = [
            1 => [
                DZ_ZI => DZ_YIN,
                DZ_CHOU => DZ_CHOU,
                DZ_YIN => DZ_ZI,
                DZ_MAO => DZ_HAI,
                DZ_CHEN => DZ_XU,
                DZ_SI => DZ_YOU,
                DZ_WU => DZ_SHEN,
                DZ_WEI => DZ_WEI,
                DZ_SHEN => DZ_WU,
                DZ_YOU => DZ_SI,
                DZ_XU => DZ_CHEN,
                DZ_HAI => DZ_MAO,
            ],
            2 => [
                DZ_ZI => DZ_MAO,
                DZ_CHOU => DZ_YIN,
                DZ_YIN => DZ_CHOU,
                DZ_MAO => DZ_ZI,
                DZ_CHEN => DZ_HAI,
                DZ_SI => DZ_XU,
                DZ_WU => DZ_YOU,
                DZ_WEI => DZ_SHEN,
                DZ_SHEN => DZ_WEI,
                DZ_YOU => DZ_WU,
                DZ_XU => DZ_SI,
                DZ_HAI => DZ_CHEN,
            ],
            3 => [
                DZ_ZI => DZ_CHEN,
                DZ_CHOU => DZ_MAO,
                DZ_YIN => DZ_YIN,
                DZ_MAO => DZ_CHOU,
                DZ_CHEN => DZ_ZI,
                DZ_SI => DZ_HAI,
                DZ_WU => DZ_XU,
                DZ_WEI => DZ_YOU,
                DZ_SHEN => DZ_SHEN,
                DZ_YOU => DZ_WEI,
                DZ_XU => DZ_WU,
                DZ_HAI => DZ_SI,
            ],
            4 => [
                DZ_ZI => DZ_SI,
                DZ_CHOU => DZ_CHEN,
                DZ_YIN => DZ_MAO,
                DZ_MAO => DZ_YIN,
                DZ_CHEN => DZ_CHOU,
                DZ_SI => DZ_ZI,
                DZ_WU => DZ_HAI,
                DZ_WEI => DZ_XU,
                DZ_SHEN => DZ_YOU,
                DZ_YOU => DZ_SHEN,
                DZ_XU => DZ_WEI,
                DZ_HAI => DZ_WU,
            ],
            5 => [
                DZ_ZI => DZ_WU,
                DZ_CHOU => DZ_SI,
                DZ_YIN => DZ_CHEN,
                DZ_MAO => DZ_MAO,
                DZ_CHEN => DZ_YIN,
                DZ_SI => DZ_CHOU,
                DZ_WU => DZ_ZI,
                DZ_WEI => DZ_HAI,
                DZ_SHEN => DZ_XU,
                DZ_YOU => DZ_YOU,
                DZ_XU => DZ_SHEN,
                DZ_HAI => DZ_WEI,
            ],
            6 => [
                DZ_ZI => DZ_WEI,
                DZ_CHOU => DZ_WU,
                DZ_YIN => DZ_SI,
                DZ_MAO => DZ_CHEN,
                DZ_CHEN => DZ_MAO,
                DZ_SI => DZ_YIN,
                DZ_WU => DZ_CHOU,
                DZ_WEI => DZ_ZI,
                DZ_SHEN => DZ_HAI,
                DZ_YOU => DZ_XU,
                DZ_XU => DZ_YOU,
                DZ_HAI => DZ_SHEN,
            ],
            7 => [
                DZ_ZI => DZ_SHEN,
                DZ_CHOU => DZ_WEI,
                DZ_YIN => DZ_WU,
                DZ_MAO => DZ_SI,
                DZ_CHEN => DZ_CHEN,
                DZ_SI => DZ_MAO,
                DZ_WU => DZ_YIN,
                DZ_WEI => DZ_CHOU,
                DZ_SHEN => DZ_ZI,
                DZ_YOU => DZ_HAI,
                DZ_XU => DZ_XU,
                DZ_HAI => DZ_YOU,
            ],
            8 => [
                DZ_ZI => DZ_YOU,
                DZ_CHOU => DZ_SHEN,
                DZ_YIN => DZ_WEI,
                DZ_MAO => DZ_WU,
                DZ_CHEN => DZ_SI,
                DZ_SI => DZ_CHEN,
                DZ_WU => DZ_MAO,
                DZ_WEI => DZ_YIN,
                DZ_SHEN => DZ_CHOU,
                DZ_YOU => DZ_ZI,
                DZ_XU => DZ_HAI,
                DZ_HAI => DZ_XU,
            ],
            9 => [
                DZ_ZI => DZ_XU,
                DZ_CHOU => DZ_YOU,
                DZ_YIN => DZ_SHEN,
                DZ_MAO => DZ_WEI,
                DZ_CHEN => DZ_WU,
                DZ_SI => DZ_SI,
                DZ_WU => DZ_CHEN,
                DZ_WEI => DZ_MAO,
                DZ_SHEN => DZ_YIN,
                DZ_YOU => DZ_CHOU,
                DZ_XU => DZ_ZI,
                DZ_HAI => DZ_HAI,
            ],
            10 => [
                DZ_ZI => DZ_HAI,
                DZ_CHOU => DZ_XU,
                DZ_YIN => DZ_YOU,
                DZ_MAO => DZ_SHEN,
                DZ_CHEN => DZ_WEI,
                DZ_SI => DZ_WU,
                DZ_WU => DZ_SI,
                DZ_WEI => DZ_CHEN,
                DZ_SHEN => DZ_MAO,
                DZ_YOU => DZ_YIN,
                DZ_XU => DZ_CHOU,
                DZ_HAI => DZ_ZI,
            ],
            11 => [
                DZ_ZI => DZ_ZI,
                DZ_CHOU => DZ_HAI,
                DZ_YIN => DZ_XU,
                DZ_MAO => DZ_YOU,
                DZ_CHEN => DZ_SHEN,
                DZ_SI => DZ_WEI,
                DZ_WU => DZ_WU,
                DZ_WEI => DZ_SI,
                DZ_SHEN => DZ_CHEN,
                DZ_YOU => DZ_MAO,
                DZ_XU => DZ_YIN,
                DZ_HAI => DZ_CHOU,
            ],
            12 => [
                DZ_ZI => DZ_CHOU,
                DZ_CHOU => DZ_ZI,
                DZ_YIN => DZ_HAI,
                DZ_MAO => DZ_XU,
                DZ_CHEN => DZ_YOU,
                DZ_SI => DZ_SHEN,
                DZ_WU => DZ_WEI,
                DZ_WEI => DZ_WU,
                DZ_SHEN => DZ_SI,
                DZ_YOU => DZ_CHEN,
                DZ_XU => DZ_MAO,
                DZ_HAI => DZ_YIN,
            ]
        ];

        return $config[$nly][$sz] ?? 12;
    }

    /**
     * 获取身宫位置
     *  从寅宫起正月，顺时针方向数到出生月之宫止，再从该宫起子时，顺时针方向数到出生时支安命宫
     * @param int $nly 农历出生月
     * @param int $sz 出生时支
     * @return int
     */
    protected function getShengong(int $nly, int $sz): int
    {
        $config = [
            1 => [
                DZ_ZI => DZ_YIN,
                DZ_CHOU => DZ_MAO,
                DZ_YIN => DZ_CHEN,
                DZ_MAO => DZ_SI,
                DZ_CHEN => DZ_WU,
                DZ_SI => DZ_WEI,
                DZ_WU => DZ_SHEN,
                DZ_WEI => DZ_YOU,
                DZ_SHEN => DZ_XU,
                DZ_YOU => DZ_HAI,
                DZ_XU => DZ_ZI,
                DZ_HAI => DZ_CHOU,
            ],
            2 => [
                DZ_ZI => DZ_MAO,
                DZ_CHOU => DZ_CHEN,
                DZ_YIN => DZ_SI,
                DZ_MAO => DZ_WU,
                DZ_CHEN => DZ_WEI,
                DZ_SI => DZ_SHEN,
                DZ_WU => DZ_YOU,
                DZ_WEI => DZ_XU,
                DZ_SHEN => DZ_HAI,
                DZ_YOU => DZ_ZI,
                DZ_XU => DZ_CHOU,
                DZ_HAI => DZ_YIN,
            ],
            3 => [
                DZ_ZI => DZ_CHEN,
                DZ_CHOU => DZ_SI,
                DZ_YIN => DZ_WU,
                DZ_MAO => DZ_WEI,
                DZ_CHEN => DZ_SHEN,
                DZ_SI => DZ_YOU,
                DZ_WU => DZ_XU,
                DZ_WEI => DZ_HAI,
                DZ_SHEN => DZ_ZI,
                DZ_YOU => DZ_CHOU,
                DZ_XU => DZ_YIN,
                DZ_HAI => DZ_MAO,
            ],
            4 => [
                DZ_ZI => DZ_SI,
                DZ_CHOU => DZ_WU,
                DZ_YIN => DZ_WEI,
                DZ_MAO => DZ_SHEN,
                DZ_CHEN => DZ_YOU,
                DZ_SI => DZ_XU,
                DZ_WU => DZ_HAI,
                DZ_WEI => DZ_ZI,
                DZ_SHEN => DZ_CHOU,
                DZ_YOU => DZ_YIN,
                DZ_XU => DZ_MAO,
                DZ_HAI => DZ_CHEN,
            ],
            5 => [
                DZ_ZI => DZ_WU,
                DZ_CHOU => DZ_WEI,
                DZ_YIN => DZ_SHEN,
                DZ_MAO => DZ_YOU,
                DZ_CHEN => DZ_XU,
                DZ_SI => DZ_HAI,
                DZ_WU => DZ_ZI,
                DZ_WEI => DZ_CHOU,
                DZ_SHEN => DZ_YIN,
                DZ_YOU => DZ_MAO,
                DZ_XU => DZ_CHEN,
                DZ_HAI => DZ_SI,
            ],
            6 => [
                DZ_ZI => DZ_WEI,
                DZ_CHOU => DZ_SHEN,
                DZ_YIN => DZ_YOU,
                DZ_MAO => DZ_XU,
                DZ_CHEN => DZ_HAI,
                DZ_SI => DZ_ZI,
                DZ_WU => DZ_CHOU,
                DZ_WEI => DZ_YIN,
                DZ_SHEN => DZ_MAO,
                DZ_YOU => DZ_CHEN,
                DZ_XU => DZ_SI,
                DZ_HAI => DZ_WU,
            ],
            7 => [
                DZ_ZI => DZ_SHEN,
                DZ_CHOU => DZ_YOU,
                DZ_YIN => DZ_XU,
                DZ_MAO => DZ_HAI,
                DZ_CHEN => DZ_ZI,
                DZ_SI => DZ_CHOU,
                DZ_WU => DZ_YIN,
                DZ_WEI => DZ_MAO,
                DZ_SHEN => DZ_CHEN,
                DZ_YOU => DZ_SI,
                DZ_XU => DZ_WU,
                DZ_HAI => DZ_WEI,
            ],
            8 => [
                DZ_ZI => DZ_YOU,
                DZ_CHOU => DZ_XU,
                DZ_YIN => DZ_HAI,
                DZ_MAO => DZ_ZI,
                DZ_CHEN => DZ_CHOU,
                DZ_SI => DZ_YIN,
                DZ_WU => DZ_MAO,
                DZ_WEI => DZ_CHEN,
                DZ_SHEN => DZ_SI,
                DZ_YOU => DZ_WU,
                DZ_XU => DZ_WEI,
                DZ_HAI => DZ_SHEN,
            ],
            9 => [
                DZ_ZI => DZ_XU,
                DZ_CHOU => DZ_HAI,
                DZ_YIN => DZ_ZI,
                DZ_MAO => DZ_CHOU,
                DZ_CHEN => DZ_YIN,
                DZ_SI => DZ_MAO,
                DZ_WU => DZ_CHEN,
                DZ_WEI => DZ_SI,
                DZ_SHEN => DZ_WU,
                DZ_YOU => DZ_WEI,
                DZ_XU => DZ_SHEN,
                DZ_HAI => DZ_YOU,
            ],
            10 => [
                DZ_ZI => DZ_HAI,
                DZ_CHOU => DZ_ZI,
                DZ_YIN => DZ_CHOU,
                DZ_MAO => DZ_YIN,
                DZ_CHEN => DZ_MAO,
                DZ_SI => DZ_CHEN,
                DZ_WU => DZ_SI,
                DZ_WEI => DZ_WU,
                DZ_SHEN => DZ_WEI,
                DZ_YOU => DZ_SHEN,
                DZ_XU => DZ_YOU,
                DZ_HAI => DZ_XU,
            ],
            11 => [
                DZ_ZI => DZ_ZI,
                DZ_CHOU => DZ_CHOU,
                DZ_YIN => DZ_YIN,
                DZ_MAO => DZ_MAO,
                DZ_CHEN => DZ_CHEN,
                DZ_SI => DZ_SI,
                DZ_WU => DZ_WU,
                DZ_WEI => DZ_WEI,
                DZ_SHEN => DZ_SHEN,
                DZ_YOU => DZ_YOU,
                DZ_XU => DZ_XU,
                DZ_HAI => DZ_HAI,
            ],
            12 => [
                DZ_ZI => DZ_CHOU,
                DZ_CHOU => DZ_YIN,
                DZ_YIN => DZ_MAO,
                DZ_MAO => DZ_CHEN,
                DZ_CHEN => DZ_SI,
                DZ_SI => DZ_WU,
                DZ_WU => DZ_WEI,
                DZ_WEI => DZ_SHEN,
                DZ_SHEN => DZ_YOU,
                DZ_YOU => DZ_XU,
                DZ_XU => DZ_HAI,
                DZ_HAI => DZ_ZI,
            ]
        ];

        return $config[$nly][$sz] ?? 12;
    }

    /**
     * 获取小限起运宫位
     * @param int $nzs 出生年支
     * @return int
     */
    protected function getXiaoxian(int $nzs): int
    {
        $config = [
            DZ_ZI => DZ_XU,
            DZ_CHOU => DZ_WEI,
            DZ_YIN => DZ_CHEN,
            DZ_MAO => DZ_CHOU,
            DZ_CHEN => DZ_XU,
            DZ_SI => DZ_WEI,
            DZ_WU => DZ_CHEN,
            DZ_WEI => DZ_CHOU,
            DZ_SHEN => DZ_XU,
            DZ_YOU => DZ_WEI,
            DZ_XU => DZ_CHEN,
            DZ_HAI => DZ_CHOU,
        ];

        return $config[$nzs] ?? 12;
    }

    /**
     * 获取五行局
     * @param int $ng 年干
     * @param int $mz 命支
     * @return int
     */
    protected function getWuxingJu(int $ng, int $mz): int
    {
        $config = [
            // 年干 => 命支 => 五行局
            TG_JIA => [
                DZ_ZI => WX_SHUI,
                DZ_CHOU => WX_SHUI,
                DZ_YIN => WX_HUO,
                DZ_MAO => WX_HUO,
                DZ_CHEN => WX_MU,
                DZ_SI => WX_MU,
                DZ_WU => WX_TU,
                DZ_WEI => WX_TU,
                DZ_SHEN => WX_JIN,
                DZ_YOU => WX_JIN,
                DZ_XU => WX_HUO,
                DZ_HAI => WX_HUO,
            ],
            TG_YI => [
                DZ_ZI => WX_HUO,
                DZ_CHOU => WX_HUO,
                DZ_YIN => WX_TU,
                DZ_MAO => WX_TU,
                DZ_CHEN => WX_JIN,
                DZ_SI => WX_JIN,
                DZ_WU => WX_MU,
                DZ_WEI => WX_MU,
                DZ_SHEN => WX_SHUI,
                DZ_YOU => WX_SHUI,
                DZ_XU => WX_TU,
                DZ_HAI => WX_TU,
            ],
            TG_BING => [
                DZ_ZI => WX_TU,
                DZ_CHOU => WX_TU,
                DZ_YIN => WX_MU,
                DZ_MAO => WX_MU,
                DZ_CHEN => WX_SHUI,
                DZ_SI => WX_SHUI,
                DZ_WU => WX_JIN,
                DZ_WEI => WX_JIN,
                DZ_SHEN => WX_HUO,
                DZ_YOU => WX_HUO,
                DZ_XU => WX_MU,
                DZ_HAI => WX_MU,
            ],
            TG_DING => [
                DZ_ZI => WX_MU,
                DZ_CHOU => WX_MU,
                DZ_YIN => WX_JIN,
                DZ_MAO => WX_JIN,
                DZ_CHEN => WX_HUO,
                DZ_SI => WX_HUO,
                DZ_WU => WX_SHUI,
                DZ_WEI => WX_SHUI,
                DZ_SHEN => WX_TU,
                DZ_YOU => WX_TU,
                DZ_XU => WX_JIN,
                DZ_HAI => WX_JIN,
            ],
            TG_WU => [
                DZ_ZI => WX_JIN,
                DZ_CHOU => WX_JIN,
                DZ_YIN => WX_SHUI,
                DZ_MAO => WX_SHUI,
                DZ_CHEN => WX_TU,
                DZ_SI => WX_TU,
                DZ_WU => WX_HUO,
                DZ_WEI => WX_HUO,
                DZ_SHEN => WX_MU,
                DZ_YOU => WX_MU,
                DZ_XU => WX_SHUI,
                DZ_HAI => WX_SHUI,
            ],
            TG_JI => [
                DZ_ZI => WX_SHUI,
                DZ_CHOU => WX_SHUI,
                DZ_YIN => WX_HUO,
                DZ_MAO => WX_HUO,
                DZ_CHEN => WX_MU,
                DZ_SI => WX_MU,
                DZ_WU => WX_TU,
                DZ_WEI => WX_TU,
                DZ_SHEN => WX_JIN,
                DZ_YOU => WX_JIN,
                DZ_XU => WX_HUO,
                DZ_HAI => WX_HUO,
            ],
            TG_GENG => [
                DZ_ZI => WX_HUO,
                DZ_CHOU => WX_HUO,
                DZ_YIN => WX_TU,
                DZ_MAO => WX_TU,
                DZ_CHEN => WX_JIN,
                DZ_SI => WX_JIN,
                DZ_WU => WX_MU,
                DZ_WEI => WX_MU,
                DZ_SHEN => WX_SHUI,
                DZ_YOU => WX_SHUI,
                DZ_XU => WX_TU,
                DZ_HAI => WX_TU,
            ],
            TG_XIN => [
                DZ_ZI => WX_TU,
                DZ_CHOU => WX_TU,
                DZ_YIN => WX_MU,
                DZ_MAO => WX_MU,
                DZ_CHEN => WX_SHUI,
                DZ_SI => WX_SHUI,
                DZ_WU => WX_JIN,
                DZ_WEI => WX_JIN,
                DZ_SHEN => WX_HUO,
                DZ_YOU => WX_HUO,
                DZ_XU => WX_MU,
                DZ_HAI => WX_MU,
            ],
            TG_REN => [
                DZ_ZI => WX_MU,
                DZ_CHOU => WX_MU,
                DZ_YIN => WX_JIN,
                DZ_MAO => WX_JIN,
                DZ_CHEN => WX_HUO,
                DZ_SI => WX_HUO,
                DZ_WU => WX_SHUI,
                DZ_WEI => WX_SHUI,
                DZ_SHEN => WX_TU,
                DZ_YOU => WX_TU,
                DZ_XU => WX_JIN,
                DZ_HAI => WX_JIN,
            ],
            TG_GUI => [
                DZ_ZI => WX_JIN,
                DZ_CHOU => WX_JIN,
                DZ_YIN => WX_SHUI,
                DZ_MAO => WX_SHUI,
                DZ_CHEN => WX_TU,
                DZ_SI => WX_TU,
                DZ_WU => WX_HUO,
                DZ_WEI => WX_HUO,
                DZ_SHEN => WX_MU,
                DZ_YOU => WX_MU,
                DZ_XU => WX_SHUI,
                DZ_HAI => WX_SHUI,
            ]
        ];

        return $config[$ng][$mz];
    }

    /**
     * 获取紫薇星所在宫位
     *  六五四三二，酉午亥辰丑
     *  局数除口数，商数向前走
     *  若见数无余，便要起虎口
     *  口数小于局，径直宫中守
     * @param int $wxj 五行局
     * @param int $nlr 出生时的农历·日· 例如农历正月初八 则为8
     * @return int
     */
    protected function getZiweiGong(int $wxj, int $nlr): int
    {
        $config = [
            1 => [
                WX_SHUI => DZ_CHOU,
                WX_MU => DZ_CHEN,
                WX_JIN => DZ_HAI,
                WX_TU => DZ_WU,
                WX_HUO => DZ_YOU,
            ],
            2 => [
                WX_SHUI => DZ_YIN,
                WX_MU => DZ_CHOU,
                WX_JIN => DZ_CHEN,
                WX_TU => DZ_HAI,
                WX_HUO => DZ_WU,
            ],
            3 => [
                WX_SHUI => DZ_YIN,
                WX_MU => DZ_YIN,
                WX_JIN => DZ_CHOU,
                WX_TU => DZ_CHEN,
                WX_HUO => DZ_HAI,
            ],
            4 => [
                WX_SHUI => DZ_MAO,
                WX_MU => DZ_SI,
                WX_JIN => DZ_YIN,
                WX_TU => DZ_CHOU,
                WX_HUO => DZ_CHEN,
            ],
            5 => [
                WX_SHUI => DZ_MAO,
                WX_MU => DZ_YIN,
                WX_JIN => DZ_ZI,
                WX_TU => DZ_YIN,
                WX_HUO => DZ_CHOU,
            ],
            6 => [
                WX_SHUI => DZ_CHEN,
                WX_MU => DZ_MAO,
                WX_JIN => DZ_SI,
                WX_TU => DZ_WEI,
                WX_HUO => DZ_YIN,
            ],
            7 => [
                WX_SHUI => DZ_CHEN,
                WX_MU => DZ_WU,
                WX_JIN => DZ_YIN,
                WX_TU => DZ_ZI,
                WX_HUO => DZ_XU,
            ],
            8 => [
                WX_SHUI => DZ_SI,
                WX_MU => DZ_MAO,
                WX_JIN => DZ_MAO,
                WX_TU => DZ_SI,
                WX_HUO => DZ_WEI,
            ],
            9 => [
                WX_SHUI => DZ_SI,
                WX_MU => DZ_CHEN,
                WX_JIN => DZ_CHOU,
                WX_TU => DZ_YIN,
                WX_HUO => DZ_ZI,
            ],
            10 => [
                WX_SHUI => DZ_WU,
                WX_MU => DZ_WEI,
                WX_JIN => DZ_WU,
                WX_TU => DZ_MAO,
                WX_HUO => DZ_SI,
            ],
            11 => [
                WX_SHUI => DZ_WU,
                WX_MU => DZ_CHEN,
                WX_JIN => DZ_MAO,
                WX_TU => DZ_SHEN,
                WX_HUO => DZ_YIN,
            ],
            12 => [
                WX_SHUI => DZ_WEI,
                WX_MU => DZ_SI,
                WX_JIN => DZ_CHEN,
                WX_TU => DZ_CHOU,
                WX_HUO => DZ_MAO,
            ],
            13 => [
                WX_SHUI => DZ_WEI,
                WX_MU => DZ_SHEN,
                WX_JIN => DZ_YIN,
                WX_TU => DZ_WU,
                WX_HUO => DZ_HAI,
            ],
            14 => [
                WX_SHUI => DZ_SHEN,
                WX_MU => DZ_SI,
                WX_JIN => DZ_WEI,
                WX_TU => DZ_MAO,
                WX_HUO => DZ_SHEN,
            ],
            15 => [
                WX_SHUI => DZ_SHEN,
                WX_MU => DZ_WU,
                WX_JIN => DZ_CHEN,
                WX_TU => DZ_CHEN,
                WX_HUO => DZ_CHOU,
            ],
            16 => [
                WX_SHUI => DZ_YOU,
                WX_MU => DZ_YOU,
                WX_JIN => DZ_SI,
                WX_TU => DZ_YOU,
                WX_HUO => DZ_WU,
            ],
            17 => [
                WX_SHUI => DZ_YOU,
                WX_MU => DZ_WU,
                WX_JIN => DZ_MAO,
                WX_TU => DZ_YIN,
                WX_HUO => DZ_MAO,
            ],
            18 => [
                WX_SHUI => DZ_XU,
                WX_MU => DZ_WEI,
                WX_JIN => DZ_SHEN,
                WX_TU => DZ_WEI,
                WX_HUO => DZ_CHEN,
            ],
            19 => [
                WX_SHUI => DZ_XU,
                WX_MU => DZ_XU,
                WX_JIN => DZ_SI,
                WX_TU => DZ_CHEN,
                WX_HUO => DZ_ZI,
            ],
            20 => [
                WX_SHUI => DZ_HAI,
                WX_MU => DZ_WEI,
                WX_JIN => DZ_WU,
                WX_TU => DZ_SI,
                WX_HUO => DZ_YOU,
            ],
            21 => [
                WX_SHUI => DZ_HAI,
                WX_MU => DZ_SHEN,
                WX_JIN => DZ_CHEN,
                WX_TU => DZ_XU,
                WX_HUO => DZ_YIN,
            ],
            22 => [
                WX_SHUI => DZ_ZI,
                WX_MU => DZ_HAI,
                WX_JIN => DZ_YOU,
                WX_TU => DZ_MAO,
                WX_HUO => DZ_WEI,
            ],
            23 => [
                WX_SHUI => DZ_ZI,
                WX_MU => DZ_SHEN,
                WX_JIN => DZ_WU,
                WX_TU => DZ_SHEN,
                WX_HUO => DZ_CHEN,
            ],
            24 => [
                WX_SHUI => DZ_CHOU,
                WX_MU => DZ_YOU,
                WX_JIN => DZ_WEI,
                WX_TU => DZ_SI,
                WX_HUO => DZ_SI,
            ],
            25 => [
                WX_SHUI => DZ_CHOU,
                WX_MU => DZ_ZI,
                WX_JIN => DZ_SI,
                WX_TU => DZ_WU,
                WX_HUO => DZ_CHOU,
            ],
            26 => [
                WX_SHUI => DZ_YIN,
                WX_MU => DZ_YOU,
                WX_JIN => DZ_XU,
                WX_TU => DZ_HAI,
                WX_HUO => DZ_XU,
            ],
            27 => [
                WX_SHUI => DZ_YIN,
                WX_MU => DZ_XU,
                WX_JIN => DZ_WEI,
                WX_TU => DZ_CHEN,
                WX_HUO => DZ_MAO,
            ],
            28 => [
                WX_SHUI => DZ_MAO,
                WX_MU => DZ_CHOU,
                WX_JIN => DZ_SHEN,
                WX_TU => DZ_YOU,
                WX_HUO => DZ_SHEN,
            ],
            29 => [
                WX_SHUI => DZ_MAO,
                WX_MU => DZ_XU,
                WX_JIN => DZ_WU,
                WX_TU => DZ_WU,
                WX_HUO => DZ_SI,
            ],
            30 => [
                WX_SHUI => DZ_CHEN,
                WX_MU => DZ_HAI,
                WX_JIN => DZ_HAI,
                WX_TU => DZ_WEI,
                WX_HUO => DZ_WU,
            ],
        ];

        return $config[$nlr][$wxj] ?? 12;
    }

    /**
     * 获取太阳位置
     *  根据紫微星所属宫位 [0,11] 获得太阳宫位
     *  子丑寅卯辰巳午未申酉戌亥
     *  酉戌亥子丑寅卯辰巳午未申
     * @param int $zwg 紫微星所在宫位
     * @return int
     */
    protected function getTaiyang(int $zwg): int
    {
        $config = [DZ_YOU, DZ_XU, DZ_HAI, DZ_ZI, DZ_CHOU, DZ_YIN, DZ_MAO, DZ_CHEN, DZ_SI, DZ_WU, DZ_WEI, DZ_SHEN];

        return $config[$zwg] ?? 12;
    }

    /**
     * 获取太阴位置
     *  根据紫微星所属宫位获得
     *  子丑寅卯辰巳午未申酉戌亥
     *  巳辰卯寅丑子亥戌酉申未午
     * @param int $zwg 紫微星所在宫位
     * @return int
     */
    protected function getTaiyin(int $zwg): int
    {
        $config = [DZ_SI, DZ_CHEN, DZ_MAO, DZ_YIN, DZ_CHOU, DZ_ZI, DZ_HAI, DZ_XU, DZ_YOU, DZ_SHEN, DZ_WEI, DZ_WU];

        return $config[$zwg] ?? 12;
    }

    /**
     * 获取贪狼位置
     *  根据紫微星所属宫位获得
     *  子丑寅卯辰巳午未申酉戌亥
     *  午巳辰卯寅丑子亥戌酉申未
     * @param int $zwg 紫微星所在宫位
     * @return int
     */
    protected function getTanlang(int $zwg): int
    {
        $config = [DZ_WU, DZ_SI, DZ_CHEN, DZ_MAO, DZ_YIN, DZ_CHOU, DZ_ZI, DZ_HAI, DZ_XU, DZ_YOU, DZ_SHEN, DZ_WEI];

        return $config[$zwg] ?? 12;
    }

    /**
     * 获取巨门位置
     *  根据紫微星所属宫位获得
     *  子丑寅卯辰巳午未申酉戌亥
     *  未午巳辰卯寅丑子亥戌酉申
     * @param int $zwg 紫微星所在宫位
     * @return int
     */
    protected function getJumen(int $zwg): int
    {
        $config = [DZ_WEI, DZ_WU, DZ_SI, DZ_CHEN, DZ_MAO, DZ_YIN, DZ_CHOU, DZ_ZI, DZ_HAI, DZ_XU, DZ_YOU, DZ_SHEN];

        return $config[$zwg] ?? 12;
    }

    /**
     * 获取廉贞位置
     *  根据紫微星所属宫位获得
     *  子丑寅卯辰巳午未申酉戌亥
     *  辰巳午未申酉戌亥子丑寅卯
     * @param int $zwg 紫微星所在宫位
     * @return int
     */
    protected function getLianzhen(int $zwg): int
    {
        $config = [DZ_CHEN, DZ_SI, DZ_WU, DZ_WEI, DZ_SHEN, DZ_YOU, DZ_XU, DZ_HAI, DZ_ZI, DZ_CHOU, DZ_YIN, DZ_MAO];

        return $config[$zwg] ?? 12;
    }

    /**
     * 获取武曲位置
     *  根据紫微星所属宫位获得
     *  子丑寅卯辰巳午未申酉戌亥
     *  申酉戌亥子丑寅卯辰巳午未
     * @param int $zwg 紫微星所在宫位
     * @return int
     */
    protected function getWuqu(int $zwg): int
    {
        $config = [DZ_SHEN, DZ_YOU, DZ_XU, DZ_HAI, DZ_ZI, DZ_CHOU, DZ_YIN, DZ_MAO, DZ_CHEN, DZ_SI, DZ_WU, DZ_WEI];

        return $config[$zwg] ?? 12;
    }

    /**
     * 获取破军位置
     *  根据紫微星所属宫位获得
     *  子丑寅卯辰巳午未申酉戌亥
     *  寅丑子亥戌酉申未午巳辰卯
     * @param int $zwg 紫微星所在宫位
     * @return int
     */
    protected function getPojun(int $zwg): int
    {
        $config = [DZ_YIN, DZ_CHOU, DZ_ZI, DZ_HAI, DZ_XU, DZ_YOU, DZ_SHEN, DZ_WEI, DZ_WU, DZ_SI, DZ_CHEN, DZ_MAO];

        return $config[$zwg] ?? 12;
    }

    /**
     * 获取天府位置
     *  根据紫微星所属宫位获得
     *  子丑寅卯辰巳午未申酉戌亥
     *  辰卯寅丑子亥戌酉申未午巳
     * @param int $zwg 紫微星所在宫位
     * @return int
     */
    protected function getTianfu(int $zwg): int
    {
        $config = [DZ_CHEN, DZ_MAO, DZ_YIN, DZ_CHOU, DZ_ZI, DZ_HAI, DZ_XU, DZ_YOU, DZ_SHEN, DZ_WEI, DZ_WU, DZ_SI];

        return $config[$zwg] ?? 12;
    }

    /**
     * 获取天梁位置
     *  根据紫微星所属宫位获得
     *  子丑寅卯辰巳午未申酉戌亥
     *  酉申未午巳辰卯寅丑子亥戌
     * @param int $zwg 紫微星所在宫位
     * @return int
     */
    protected function getTianliang(int $zwg): int
    {
        $config = [DZ_YOU, DZ_SHEN, DZ_WEI, DZ_WU, DZ_SI, DZ_CHEN, DZ_MAO, DZ_YIN, DZ_CHOU, DZ_ZI, DZ_HAI, DZ_XU];

        return $config[$zwg] ?? 12;
    }

    /**
     * 获取天机位置
     *  根据紫微星所属宫位获得
     *  子丑寅卯辰巳午未申酉戌亥
     *  亥子丑寅卯辰巳午未申酉戌
     * @param int $zwg 紫微星所在宫位
     * @return int
     */
    protected function getTianji(int $zwg): int
    {
        $config = [DZ_HAI, DZ_ZI, DZ_CHOU, DZ_YIN, DZ_MAO, DZ_CHEN, DZ_SI, DZ_WU, DZ_WEI, DZ_SHEN, DZ_YOU, DZ_XU];

        return $config[$zwg] ?? 12;
    }

    /**
     * 获取天同位置
     *  根据紫微星所属宫位获得
     *  子丑寅卯辰巳午未申酉戌亥
     *  未申酉戌亥子丑寅卯辰巳午
     * @param int $zwg 紫微星所在宫位
     * @return int
     */
    protected function getTiantong(int $zwg): int
    {
        $config = [DZ_WEI, DZ_SHEN, DZ_YOU, DZ_XU, DZ_HAI, DZ_ZI, DZ_CHOU, DZ_YIN, DZ_MAO, DZ_CHEN, DZ_SI, DZ_WU];

        return $config[$zwg] ?? 12;
    }

    /**
     * 获取天相位置
     *  根据紫微星所属宫位获得
     *  子丑寅卯辰巳午未申酉戌亥
     *  申未午巳辰卯寅丑子亥戌酉
     * @param int $zwg 紫微星所在宫位
     * @return int
     */
    protected function getTianxiang(int $zwg): int
    {
        $config = [DZ_SHEN, DZ_WEI, DZ_WU, DZ_SI, DZ_CHEN, DZ_MAO, DZ_YIN, DZ_CHOU, DZ_ZI, DZ_HAI, DZ_XU, DZ_YOU];

        return $config[$zwg] ?? 12;
    }

    /**
     * 获取七杀位置
     *  根据紫微星所属宫位获得 [0,11]
     *  子丑寅卯辰巳午未申酉戌亥
     *  戌酉申未午巳辰卯寅丑子亥
     * @param int $zwg 紫微星所在宫位
     * @return int
     */
    protected function getQisha(int $zwg): int
    {
        $config = [DZ_XU, DZ_YOU, DZ_SHEN, DZ_WEI, DZ_WU, DZ_SI, DZ_CHEN, DZ_MAO, DZ_YIN, DZ_CHOU, DZ_ZI, DZ_HAI];

        return $config[$zwg] ?? 12;
    }

    /**
     * 获取左辅位置
     *  根据农历生月获得
     *  1、2、3、4、5、6、7、8、9、10、11、12
     *  辰、巳、午、未、申、酉、戌、亥、子、丑、寅、卯
     * @param int $nly 农历生月  [1,12]
     * @return int
     */
    protected function getZuofu(int $nly): int
    {
        $config = [12, DZ_CHEN, DZ_SI, DZ_WU, DZ_WEI, DZ_SHEN, DZ_YOU, DZ_XU, DZ_HAI, DZ_ZI, DZ_CHOU, DZ_YIN, DZ_MAO];

        return $config[$nly] ?? 12;
    }

    /**
     * 获取右弼位置
     *  根据农历生月获得
     * @param int $nly 农历生月  [1,12]
     * @return int
     */
    protected function getYoubi(int $nly): int
    {
        $config = [12, DZ_XU, DZ_YOU, DZ_SHEN, DZ_WEI, DZ_WU, DZ_SI, DZ_CHEN, DZ_MAO, DZ_YIN, DZ_CHOU, DZ_ZI, DZ_HAI];

        return $config[$nly] ?? 12;
    }

    /**
     * 获取天魁位置
     *  根据出生年干获得
     *  甲乙丙丁戊己庚辛壬癸
     *  丑子亥亥丑子丑午卯卯
     *          安魁钺诀
     *  甲戊庚牛羊，乙己鼠猴乡，丙丁猪鸡位
     *  壬癸兔蛇藏，辛年逢马虎，魁钺贵人方
     * @param int $ng 出生年干
     * @return int
     */
    protected function getTiankui(int $ng): int
    {
        $config = [DZ_CHOU, DZ_ZI, DZ_HAI, DZ_HAI, DZ_CHOU, DZ_ZI, DZ_CHOU, DZ_WU, DZ_MAO, DZ_MAO];
        $res = $config[$ng] ?? 12;
        if ($this->setting['an_kuiyue'] === 1 && $ng === TG_XIN)
        {
            /**
             * 六辛逢虎马
             */
            $res = DZ_YIN;
        }
        return $res;
    }

    /**
     * 获取天钺位置
     *  根据出生年干获得
     *  甲乙丙丁戊己庚辛壬癸
     *  未申酉酉未申未寅巳巳
     *          安魁钺诀
     *  甲戊庚牛羊，乙己鼠猴乡，丙丁猪鸡位
     *  壬癸兔蛇藏，辛年逢马虎，魁钺贵人方
     * @param int $ng 出生年干
     * @return int
     */
    protected function getTianyue(int $ng): int
    {
        $config = [DZ_WEI, DZ_SHEN, DZ_YOU, DZ_YOU, DZ_WEI, DZ_SHEN, DZ_WEI, DZ_YIN, DZ_SI, DZ_SI];
        $res = $config[$ng] ?? 12;
        //
        if ($this->setting['an_kuiyue'] === 1 && $ng === TG_XIN)
        {
            /**
             * 六辛逢虎马
             */
            $res = DZ_WU;
        }
        return $res;
    }

    /**
     * 获取禄存位置
     *  根据出生年干获得
     *  甲乙丙丁戊己庚辛壬癸
     *  寅卯巳午巳午申酉亥子
     *                 安禄存、擎羊、陀罗
     *  甲禄到寅宫，乙禄居卯府，丙戊禄在巳，丁巳禄在午，庚禄定居申
     *  辛禄酉上补，壬禄亥中藏，癸禄居子户，禄前擎羊当，禄后陀罗府
     * @param int $ng 出生年干
     * @return int
     */
    protected function getLucun(int $ng): int
    {
        $config = [DZ_YIN, DZ_MAO, DZ_SI, DZ_WU, DZ_SI, DZ_WU, DZ_SHEN, DZ_YOU, DZ_HAI, DZ_ZI];

        return $config[$ng] ?? 12;
    }

    /**
     * 获取天马位置
     *  根据出生年支获得
     *  子丑寅卯辰巳午未申酉戌亥
     *  寅亥申巳寅亥申巳寅亥申巳
     * @param int $nz 出生年支
     * @return int
     */
    protected function getTianma(int $nz): int
    {
        $config = [DZ_YIN, DZ_HAI, DZ_SHEN, DZ_SI, DZ_YIN, DZ_HAI, DZ_SHEN, DZ_SI, DZ_YIN, DZ_HAI, DZ_SHEN, DZ_SI];

        return $config[$nz] ?? 12;
    }

    /**
     * 获取文昌位置
     *  根据出生时支获得
     *  子丑寅卯辰巳午未申酉戌亥
     *  戌酉申未午巳辰卯寅丑子亥
     * @param int $sz 出生时支
     * @return int
     */
    protected function getWenchang(int $sz): int
    {
        $config = [DZ_XU, DZ_YOU, DZ_SHEN, DZ_WEI, DZ_WU, DZ_SI, DZ_CHEN, DZ_MAO, DZ_YIN, DZ_CHOU, DZ_ZI, DZ_HAI];

        return $config[$sz] ?? 12;
    }

    /**
     * 获取文曲位置
     *  根据出生时支获得
     *  子丑寅卯辰巳午未申酉戌亥
     *  辰巳午未申酉戌亥子丑寅卯
     * @param int $sz 出生时支
     * @return int
     */
    protected function getWenqu(int $sz): int
    {
        $config = [DZ_CHEN, DZ_SI, DZ_WU, DZ_WEI, DZ_SHEN, DZ_YOU, DZ_XU, DZ_HAI, DZ_ZI, DZ_CHOU, DZ_YIN, DZ_MAO];

        return $config[$sz] ?? 12;
    }

    /**
     * 获取擎羊位置
     *  根据出生年干获得
     *  甲乙丙丁戊己庚辛壬癸
     *  卯辰午未午未酉戌子丑
     * @param int $ng 出生年干
     * @return int
     */
    protected function getQingyang(int $ng): int
    {
        $config = [DZ_MAO, DZ_CHEN, DZ_WU, DZ_WEI, DZ_WU, DZ_WEI, DZ_YOU, DZ_XU, DZ_ZI, DZ_CHOU];

        return $config[$ng] ?? 12;
    }

    /**
     * 获取陀罗位置
     *  根据出生年干获得
     *  甲乙丙丁戊己庚辛壬癸
     *  丑寅辰巳辰巳未申戌亥
     * @param int $ng 出生年干
     * @return int
     */
    protected function getTuoluo(int $ng): int
    {
        $config = [DZ_CHOU, DZ_YIN, DZ_CHEN, DZ_SI, DZ_CHEN, DZ_SI, DZ_WEI, DZ_SHEN, DZ_XU, DZ_HAI];

        return $config[$ng] ?? 12;
    }

    /**
     * 获取火星位置
     *  根据出生年支和时支获得
     *    寅午戌
     *      子丑寅卯辰巳午未申酉戌亥
     *      丑寅卯辰巳午未申酉戌亥子
     *    申子辰
     *      子丑寅卯辰巳午未申酉戌亥
     *      寅卯辰巳午未申酉戌亥子丑
     *    巳酉丑
     *      子丑寅卯辰巳午未申酉戌亥
     *      卯辰巳午未申酉戌亥子丑寅
     *    亥卯未
     *      子丑寅卯辰巳午未申酉戌亥
     *      酉戌亥子丑寅卯辰巳午未申
     * @param int $nz 出生年支
     * @param int $sz 出生时支
     * @return int
     */
    protected function getHuoxing(int $nz, int $sz): int
    {
        $config = [
            DZ_ZI => [DZ_YIN, DZ_MAO, DZ_CHEN, DZ_SI, DZ_WU, DZ_WEI, DZ_SHEN, DZ_YOU, DZ_XU, DZ_HAI, DZ_ZI, DZ_CHOU],
            DZ_CHOU => [DZ_MAO, DZ_CHEN, DZ_SI, DZ_WU, DZ_WEI, DZ_SHEN, DZ_YOU, DZ_XU, DZ_HAI, DZ_ZI, DZ_CHOU, DZ_YIN],
            DZ_YIN => [DZ_CHOU, DZ_YIN, DZ_MAO, DZ_CHEN, DZ_SI, DZ_WU, DZ_WEI, DZ_SHEN, DZ_YOU, DZ_XU, DZ_HAI, DZ_ZI],
            DZ_MAO => [DZ_YOU, DZ_XU, DZ_HAI, DZ_ZI, DZ_CHOU, DZ_YIN, DZ_MAO, DZ_CHEN, DZ_SI, DZ_WU, DZ_WEI, DZ_SHEN],
            DZ_CHEN => [DZ_YIN, DZ_MAO, DZ_CHEN, DZ_SI, DZ_WU, DZ_WEI, DZ_SHEN, DZ_YOU, DZ_XU, DZ_HAI, DZ_ZI, DZ_CHOU],
            DZ_SI => [DZ_MAO, DZ_CHEN, DZ_SI, DZ_WU, DZ_WEI, DZ_SHEN, DZ_YOU, DZ_XU, DZ_HAI, DZ_ZI, DZ_CHOU, DZ_YIN],
            DZ_WU => [DZ_CHOU, DZ_YIN, DZ_MAO, DZ_CHEN, DZ_SI, DZ_WU, DZ_WEI, DZ_SHEN, DZ_YOU, DZ_XU, DZ_HAI, DZ_ZI],
            DZ_WEI => [DZ_YOU, DZ_XU, DZ_HAI, DZ_ZI, DZ_CHOU, DZ_YIN, DZ_MAO, DZ_CHEN, DZ_SI, DZ_WU, DZ_WEI, DZ_SHEN],
            DZ_SHEN => [DZ_YIN, DZ_MAO, DZ_CHEN, DZ_SI, DZ_WU, DZ_WEI, DZ_SHEN, DZ_YOU, DZ_XU, DZ_HAI, DZ_ZI, DZ_CHOU],
            DZ_YOU => [DZ_MAO, DZ_CHEN, DZ_SI, DZ_WU, DZ_WEI, DZ_SHEN, DZ_YOU, DZ_XU, DZ_HAI, DZ_ZI, DZ_CHOU, DZ_YIN],
            DZ_XU => [DZ_CHOU, DZ_YIN, DZ_MAO, DZ_CHEN, DZ_SI, DZ_WU, DZ_WEI, DZ_SHEN, DZ_YOU, DZ_XU, DZ_HAI, DZ_ZI],
            DZ_HAI => [DZ_YOU, DZ_XU, DZ_HAI, DZ_ZI, DZ_CHOU, DZ_YIN, DZ_MAO, DZ_CHEN, DZ_SI, DZ_WU, DZ_WEI, DZ_SHEN],
        ];
        return $config[$nz][$sz] ?? 12;
    }

    /**
     * 获取铃星位置
     *  根据出生年支和时支获得
     *    寅午戌
     *      子丑寅卯辰巳午未申酉戌亥
     *      卯辰巳午未申酉戌亥子丑寅
     *    申子辰
     *      子丑寅卯辰巳午未申酉戌亥
     *      戌亥子丑寅卯辰巳午未申酉
     *    巳酉丑
     *      子丑寅卯辰巳午未申酉戌亥
     *      戌亥子丑寅卯辰巳午未申酉
     *    亥卯未
     *      子丑寅卯辰巳午未申酉戌亥
     *      戌亥子丑寅卯辰巳午未申酉
     * @param int $nz 出生年支
     * @param int $sz 出生时支
     * @return int
     */
    protected function getLingxing(int $nz, int $sz): int
    {
        $config = [
            DZ_ZI => [DZ_XU, DZ_HAI, DZ_ZI, DZ_CHOU, DZ_YIN, DZ_MAO, DZ_CHEN, DZ_SI, DZ_WU, DZ_WEI, DZ_SHEN, DZ_YOU],
            DZ_CHOU => [DZ_XU, DZ_HAI, DZ_ZI, DZ_CHOU, DZ_YIN, DZ_MAO, DZ_CHEN, DZ_SI, DZ_WU, DZ_WEI, DZ_SHEN, DZ_YOU],
            DZ_YIN => [DZ_MAO, DZ_CHEN, DZ_SI, DZ_WU, DZ_WEI, DZ_SHEN, DZ_YOU, DZ_XU, DZ_HAI, DZ_ZI, DZ_CHOU, DZ_YIN],
            DZ_MAO => [DZ_XU, DZ_HAI, DZ_ZI, DZ_CHOU, DZ_YIN, DZ_MAO, DZ_CHEN, DZ_SI, DZ_WU, DZ_WEI, DZ_SHEN, DZ_YOU],
            DZ_CHEN => [DZ_XU, DZ_HAI, DZ_ZI, DZ_CHOU, DZ_YIN, DZ_MAO, DZ_CHEN, DZ_SI, DZ_WU, DZ_WEI, DZ_SHEN, DZ_YOU],
            DZ_SI => [DZ_XU, DZ_HAI, DZ_ZI, DZ_CHOU, DZ_YIN, DZ_MAO, DZ_CHEN, DZ_SI, DZ_WU, DZ_WEI, DZ_SHEN, DZ_YOU],
            DZ_WU => [DZ_MAO, DZ_CHEN, DZ_SI, DZ_WU, DZ_WEI, DZ_SHEN, DZ_YOU, DZ_XU, DZ_HAI, DZ_ZI, DZ_CHOU, DZ_YIN],
            DZ_WEI => [DZ_XU, DZ_HAI, DZ_ZI, DZ_CHOU, DZ_YIN, DZ_MAO, DZ_CHEN, DZ_SI, DZ_WU, DZ_WEI, DZ_SHEN, DZ_YOU],
            DZ_SHEN => [DZ_XU, DZ_HAI, DZ_ZI, DZ_CHOU, DZ_YIN, DZ_MAO, DZ_CHEN, DZ_SI, DZ_WU, DZ_WEI, DZ_SHEN, DZ_YOU],
            DZ_YOU => [DZ_XU, DZ_HAI, DZ_ZI, DZ_CHOU, DZ_YIN, DZ_MAO, DZ_CHEN, DZ_SI, DZ_WU, DZ_WEI, DZ_SHEN, DZ_YOU],
            DZ_XU => [DZ_MAO, DZ_CHEN, DZ_SI, DZ_WU, DZ_WEI, DZ_SHEN, DZ_YOU, DZ_XU, DZ_HAI, DZ_ZI, DZ_CHOU, DZ_YIN],
            DZ_HAI => [DZ_XU, DZ_HAI, DZ_ZI, DZ_CHOU, DZ_YIN, DZ_MAO, DZ_CHEN, DZ_SI, DZ_WU, DZ_WEI, DZ_SHEN, DZ_YOU],
        ];
        return $config[$nz][$sz] ?? 12;
    }

    /**
     * 获取地空位置
     *  根据出生时支获取，以亥宫起子时，逆数到出生时辰安地空星。
     *  子丑寅卯辰巳午未申酉戌亥
     *  亥子丑寅卯辰巳午未申酉戌
     * @param int $sz 出生时支
     * @return int
     */
    protected function getDikong(int $sz): int
    {
        $config = [DZ_HAI, DZ_XU, DZ_YOU, DZ_SHEN, DZ_WEI, DZ_WU, DZ_SI, DZ_CHEN, DZ_MAO, DZ_YIN, DZ_CHOU, DZ_ZI];

        return $config[$sz] ?? 12;
    }

    /**
     * 获取地劫位置
     *  根据出生时支获取，以亥宫起子时，顺数到生时安地劫星。
     *  子丑寅卯辰巳午未申酉戌亥
     *  亥子丑寅卯辰巳午未申酉戌
     * @param int $sz 出生时支
     * @return int
     */
    protected function getDijie(int $sz): int
    {
        $config = [DZ_HAI, DZ_ZI, DZ_CHOU, DZ_YIN, DZ_MAO, DZ_CHEN, DZ_SI, DZ_WU, DZ_WEI, DZ_SHEN, DZ_YOU, DZ_XU];

        return $config[$sz] ?? 12;
    }

    /**
     * 获取阴煞
     *  根据生月
     * @param int $nly
     * @return int
     */
    protected function getYinsha(int $nly): int
    {
        $config = [
            1 => DZ_YIN,
            2 => DZ_ZI,
            3 => DZ_XU,
            4 => DZ_SHEN,
            5 => DZ_WU,
            6 => DZ_CHEN,
            7 => DZ_YIN,
            8 => DZ_ZI,
            9 => DZ_XU,
            10 => DZ_SHEN,
            11 => DZ_WU,
            12 => DZ_CHEN,
        ];
        return $config[$nly] ?? 12;
    }

    /**
     * 获取天刑
     *  根据生月
     * @param int $nly
     * @return int
     */
    protected function getTianxing(int $nly): int
    {
        $config = [
            1 => DZ_YOU,
            2 => DZ_XU,
            3 => DZ_HAI,
            4 => DZ_ZI,
            5 => DZ_CHOU,
            6 => DZ_YIN,
            7 => DZ_MAO,
            8 => DZ_CHEN,
            9 => DZ_SI,
            10 => DZ_WU,
            11 => DZ_WEI,
            12 => DZ_SHEN,
        ];
        return $config[$nly] ?? 12;
    }

    /**
     * 获取天姚
     *  根据生月
     * @param int $nly
     * @return int
     */
    protected function getTianyao(int $nly): int
    {
        $config = [
            1 => DZ_CHOU,
            2 => DZ_YIN,
            3 => DZ_MAO,
            4 => DZ_CHEN,
            5 => DZ_SI,
            6 => DZ_WU,
            7 => DZ_WEI,
            8 => DZ_SHEN,
            9 => DZ_YOU,
            10 => DZ_XU,
            11 => DZ_HAI,
            12 => DZ_ZI,
        ];
        return $config[$nly] ?? 12;
    }

    /**
     * 获取天月
     *  根据生月
     * @param int $nly
     * @return int
     */
    protected function getTianyue2(int $nly): int
    {
        $config = [
            1 => DZ_XU,
            2 => DZ_SI,
            3 => DZ_CHEN,
            4 => DZ_YIN,
            5 => DZ_WEI,
            6 => DZ_MAO,
            7 => DZ_HAI,
            8 => DZ_WEI,
            9 => DZ_YIN,
            10 => DZ_WU,
            11 => DZ_XU,
            12 => DZ_YIN,
        ];
        return $config[$nly] ?? 12;
    }

    /**
     * 获取天巫
     *  根据生月
     *  巳申亥寅巳申亥寅巳申亥寅
     * @param int $nly
     * @return int
     */
    protected function getTianwu(int $nly): int
    {
        // 陆斌兆先生讲义中的天巫星安法
        // 参考文献：https://www.douban.com/note/811756260/?_i=8897507bNIprmg
//        $config = [
//            1 => DZ_SI,
//            2 => DZ_SHEN,
//            3 => DZ_HAI,
//            4 => DZ_YIN,
//            5 => DZ_SI,
//            6 => DZ_SHEN,
//            7 => DZ_HAI,
//            8 => DZ_YIN,
//            9 => DZ_SI,
//            10 => DZ_SHEN,
//            11 => DZ_HAI,
//            12 => DZ_YIN,
//        ];
        // 坊间流传的排法
        $config = [
            1 => DZ_SI,
            2 => DZ_SHEN,
            3 => DZ_YIN,
            4 => DZ_HAI,
            5 => DZ_SI,
            6 => DZ_SHEN,
            7 => DZ_YIN,
            8 => DZ_HAI,
            9 => DZ_SI,
            10 => DZ_SHEN,
            11 => DZ_YIN,
            12 => DZ_HAI,
        ];
        return $config[$nly] ?? 12;
    }

    /**
     * 获取天喜
     *  根据出生年支
     * @param int $nz 出生年支
     * @return int
     */
    protected function getTianxi(int $nz): int
    {
        $config = [
            DZ_ZI => DZ_YOU,
            DZ_CHOU => DZ_SHEN,
            DZ_YIN => DZ_WEI,
            DZ_MAO => DZ_WU,
            DZ_CHEN => DZ_SI,
            DZ_SI => DZ_CHEN,
            DZ_WU => DZ_MAO,
            DZ_WEI => DZ_YIN,
            DZ_SHEN => DZ_CHOU,
            DZ_YOU => DZ_ZI,
            DZ_XU => DZ_HAI,
            DZ_HAI => DZ_XU,
        ];

        return $config[$nz] ?? 12;
    }

    /**
     * 获取天虚
     *  根据出生年支
     * @param int $nz 出生年支
     * @return int
     */
    protected function getTianxu(int $nz): int
    {
        $config = [
            DZ_ZI => DZ_WU,
            DZ_CHOU => DZ_WEI,
            DZ_YIN => DZ_SHEN,
            DZ_MAO => DZ_YOU,
            DZ_CHEN => DZ_XU,
            DZ_SI => DZ_HAI,
            DZ_WU => DZ_ZI,
            DZ_WEI => DZ_CHOU,
            DZ_SHEN => DZ_YIN,
            DZ_YOU => DZ_MAO,
            DZ_XU => DZ_CHEN,
            DZ_HAI => DZ_SI,
        ];

        return $config[$nz] ?? 12;
    }

    /**
     * 获取天哭
     *  根据出生年支
     * @param int $nz 出生年支
     * @return int
     */
    protected function getTianku(int $nz): int
    {
        $config = [
            DZ_ZI => DZ_WU,
            DZ_CHOU => DZ_SI,
            DZ_YIN => DZ_CHEN,
            DZ_MAO => DZ_MAO,
            DZ_CHEN => DZ_YIN,
            DZ_SI => DZ_CHOU,
            DZ_WU => DZ_ZI,
            DZ_WEI => DZ_HAI,
            DZ_SHEN => DZ_XU,
            DZ_YOU => DZ_YOU,
            DZ_XU => DZ_SHEN,
            DZ_HAI => DZ_WEI,
        ];

        return $config[$nz] ?? 12;
    }

    /**
     * 获取天德
     *  根据出生年支
     * @param int $nz 出生年支
     * @return int
     */
    protected function getTiande(int $nz): int
    {
        $config = [
            DZ_ZI => DZ_YOU,
            DZ_CHOU => DZ_XU,
            DZ_YIN => DZ_HAI,
            DZ_MAO => DZ_ZI,
            DZ_CHEN => DZ_CHOU,
            DZ_SI => DZ_YIN,
            DZ_WU => DZ_MAO,
            DZ_WEI => DZ_CHEN,
            DZ_SHEN => DZ_SI,
            DZ_YOU => DZ_WU,
            DZ_XU => DZ_WEI,
            DZ_HAI => DZ_SHEN,
        ];

        return $config[$nz] ?? 12;
    }

    /**
     * 获取月德
     *  根据出生年支
     *  巳午未申酉戌亥子丑寅卯辰
     * @param int $nz 出生年支
     * @return int
     */
    protected function getYuede(int $nz): int
    {
        $config = [
            DZ_ZI => DZ_SI,
            DZ_CHOU => DZ_WU,
            DZ_YIN => DZ_WEI,
            DZ_MAO => DZ_SHEN,
            DZ_CHEN => DZ_YOU,
            DZ_SI => DZ_XU,
            DZ_WU => DZ_HAI,
            DZ_WEI => DZ_ZI,
            DZ_SHEN => DZ_CHOU,
            DZ_YOU => DZ_YIN,
            DZ_XU => DZ_MAO,
            DZ_HAI => DZ_CHEN,
        ];

        return $config[$nz] ?? 12;
    }

    /**
     * 获取天空
     *  根据出生年支
     *  丑寅卯辰巳午未申酉戌亥子
     * @param int $nz 出生年支
     * @return int
     */
    protected function getTiankong(int $nz): int
    {
        $config = [
            DZ_ZI => DZ_CHOU,
            DZ_CHOU => DZ_YIN,
            DZ_YIN => DZ_MAO,
            DZ_MAO => DZ_CHEN,
            DZ_CHEN => DZ_SI,
            DZ_SI => DZ_WU,
            DZ_WU => DZ_WEI,
            DZ_WEI => DZ_SHEN,
            DZ_SHEN => DZ_YOU,
            DZ_YOU => DZ_XU,
            DZ_XU => DZ_HAI,
            DZ_HAI => DZ_ZI,
        ];

        return $config[$nz] ?? 12;
    }

    /**
     * 获取红鸾
     *  根据出生年支
     * @param int $nz 出生年支
     * @return int
     */
    protected function getHongluan(int $nz): int
    {
        $config = [
            DZ_ZI => DZ_MAO,
            DZ_CHOU => DZ_YIN,
            DZ_YIN => DZ_CHOU,
            DZ_MAO => DZ_ZI,
            DZ_CHEN => DZ_HAI,
            DZ_SI => DZ_XU,
            DZ_WU => DZ_YOU,
            DZ_WEI => DZ_SHEN,
            DZ_SHEN => DZ_WEI,
            DZ_YOU => DZ_WU,
            DZ_XU => DZ_SI,
            DZ_HAI => DZ_CHEN,
        ];

        return $config[$nz] ?? 12;
    }

    /**
     * 获取龙池
     *  根据出生年支
     * @param int $nz 出生年支
     * @return int
     */
    protected function getLongchi(int $nz): int
    {
        $config = [
            DZ_ZI => DZ_CHEN,
            DZ_CHOU => DZ_SI,
            DZ_YIN => DZ_WU,
            DZ_MAO => DZ_WEI,
            DZ_CHEN => DZ_SHEN,
            DZ_SI => DZ_YOU,
            DZ_WU => DZ_XU,
            DZ_WEI => DZ_HAI,
            DZ_SHEN => DZ_ZI,
            DZ_YOU => DZ_CHOU,
            DZ_XU => DZ_YIN,
            DZ_HAI => DZ_MAO,
        ];

        return $config[$nz] ?? 12;
    }

    /**
     * 获取凤阁
     *  根据出生年支
     * @param int $nz 出生年支
     * @return int
     */
    protected function getFengge(int $nz): int
    {
        $config = [
            DZ_ZI => DZ_XU,
            DZ_CHOU => DZ_YOU,
            DZ_YIN => DZ_SHEN,
            DZ_MAO => DZ_WEI,
            DZ_CHEN => DZ_WU,
            DZ_SI => DZ_SI,
            DZ_WU => DZ_CHEN,
            DZ_WEI => DZ_MAO,
            DZ_SHEN => DZ_YIN,
            DZ_YOU => DZ_CHOU,
            DZ_XU => DZ_ZI,
            DZ_HAI => DZ_HAI,
        ];

        return $config[$nz] ?? 12;
    }

    /**
     * 获取孤辰
     *  根据出生年支
     * @param int $nz 出生年支
     * @return int
     */
    protected function getGuchen(int $nz): int
    {
        $config = [
            DZ_ZI => DZ_YIN,
            DZ_CHOU => DZ_YIN,
            DZ_YIN => DZ_SI,
            DZ_MAO => DZ_SI,
            DZ_CHEN => DZ_SI,
            DZ_SI => DZ_SHEN,
            DZ_WU => DZ_SHEN,
            DZ_WEI => DZ_SHEN,
            DZ_SHEN => DZ_HAI,
            DZ_YOU => DZ_HAI,
            DZ_XU => DZ_HAI,
            DZ_HAI => DZ_YIN,
        ];

        return $config[$nz] ?? 12;
    }

    /**
     * 获取寡宿
     *  根据出生年支
     * @param int $nz 出生年支
     * @return int
     */
    protected function getGuaxiu(int $nz): int
    {
        $config = [
            DZ_ZI => DZ_XU,
            DZ_CHOU => DZ_XU,
            DZ_YIN => DZ_CHOU,
            DZ_MAO => DZ_CHOU,
            DZ_CHEN => DZ_CHOU,
            DZ_SI => DZ_CHEN,
            DZ_WU => DZ_CHEN,
            DZ_WEI => DZ_CHEN,
            DZ_SHEN => DZ_WEI,
            DZ_YOU => DZ_WEI,
            DZ_XU => DZ_WEI,
            DZ_HAI => DZ_XU,
        ];

        return $config[$nz] ?? 12;
    }

    /**
     * 获取破碎
     *  根据出生年支
     * @param int $nz 出生年支
     * @return int
     */
    protected function getPosui(int $nz): int
    {
        $config = [
            DZ_ZI => DZ_SI,
            DZ_CHOU => DZ_CHOU,
            DZ_YIN => DZ_YOU,
            DZ_MAO => DZ_SI,
            DZ_CHEN => DZ_CHOU,
            DZ_SI => DZ_YOU,
            DZ_WU => DZ_SI,
            DZ_WEI => DZ_CHOU,
            DZ_SHEN => DZ_YOU,
            DZ_YOU => DZ_SI,
            DZ_XU => DZ_CHOU,
            DZ_HAI => DZ_YOU,
        ];

        return $config[$nz] ?? 12;
    }

    /**
     * 获取大耗
     *  根据出生年支
     * @param int $nz 出生年支
     * @return int
     */
    protected function getDahao(int $nz): int
    {
        $config = [
            DZ_ZI => DZ_WEI,
            DZ_CHOU => DZ_WU,
            DZ_YIN => DZ_YOU,
            DZ_MAO => DZ_SHEN,
            DZ_CHEN => DZ_HAI,
            DZ_SI => DZ_XU,
            DZ_WU => DZ_CHOU,
            DZ_WEI => DZ_ZI,
            DZ_SHEN => DZ_MAO,
            DZ_YOU => DZ_YIN,
            DZ_XU => DZ_SI,
            DZ_HAI => DZ_CHEN,
        ];

        return $config[$nz] ?? 12;
    }

    /**
     * 获取华盖
     *  根据出生年支
     * @param int $nz 出生年支
     * @return int
     */
    protected function getHuagai(int $nz): int
    {
        $config = [
            DZ_ZI => DZ_CHEN,
            DZ_CHOU => DZ_CHOU,
            DZ_YIN => DZ_XU,
            DZ_MAO => DZ_WEI,
            DZ_CHEN => DZ_CHEN,
            DZ_SI => DZ_CHOU,
            DZ_WU => DZ_XU,
            DZ_WEI => DZ_WEI,
            DZ_SHEN => DZ_CHEN,
            DZ_YOU => DZ_CHOU,
            DZ_XU => DZ_XU,
            DZ_HAI => DZ_WEI,
        ];

        return $config[$nz] ?? 12;
    }

    /**
     * 获取解神
     *  根据农历出生月
     *  申申戌戌子子寅寅辰辰午午
     * @param int $nly 农历出生月
     * @return int
     */
    protected function getXieshen(int $nly): int
    {
        $config = [
            1 => DZ_SHEN,
            2 => DZ_SHEN,
            3 => DZ_XU,
            4 => DZ_XU,
            5 => DZ_ZI,
            6 => DZ_ZI,
            7 => DZ_YIN,
            8 => DZ_YIN,
            9 => DZ_CHEN,
            10 => DZ_CHEN,
            11 => DZ_WU,
            12 => DZ_WU,
        ];

        return $config[$nly] ?? 12;
    }

    /**
     * 获取年解
     *  根据出生年支
     * @param int $nz 出生年支
     * @return int
     */
    protected function getNianxie(int $nz): int
    {
        $config = [
            DZ_ZI => DZ_XU,
            DZ_CHOU => DZ_YOU,
            DZ_YIN => DZ_SHEN,
            DZ_MAO => DZ_WEI,
            DZ_CHEN => DZ_WU,
            DZ_SI => DZ_SI,
            DZ_WU => DZ_CHEN,
            DZ_WEI => DZ_MAO,
            DZ_SHEN => DZ_YIN,
            DZ_YOU => DZ_CHOU,
            DZ_XU => DZ_ZI,
            DZ_HAI => DZ_HAI,
        ];

        return $config[$nz] ?? 12;
    }

    /**
     * 获取咸池
     *  根据出生年支
     * @param int $nz 出生年支
     * @return int
     */
    protected function getXianchi(int $nz): int
    {
        $config = [
            DZ_ZI => DZ_YOU,
            DZ_CHOU => DZ_WU,
            DZ_YIN => DZ_MAO,
            DZ_MAO => DZ_ZI,
            DZ_CHEN => DZ_YOU,
            DZ_SI => DZ_WU,
            DZ_WU => DZ_MAO,
            DZ_WEI => DZ_ZI,
            DZ_SHEN => DZ_YOU,
            DZ_YOU => DZ_WU,
            DZ_XU => DZ_MAO,
            DZ_HAI => DZ_ZI,
        ];

        return $config[$nz] ?? 12;
    }

    /**
     * 获取劫煞
     *  根据出生年支
     * @param int $nz 出生年支
     * @return int
     */
    protected function getJiesha(int $nz): int
    {
        $config = [
            DZ_ZI => DZ_SI,
            DZ_CHOU => DZ_YIN,
            DZ_YIN => DZ_HAI,
            DZ_MAO => DZ_SHEN,
            DZ_CHEN => DZ_SI,
            DZ_SI => DZ_YIN,
            DZ_WU => DZ_HAI,
            DZ_WEI => DZ_SHEN,
            DZ_SHEN => DZ_SI,
            DZ_YOU => DZ_YIN,
            DZ_XU => DZ_HAI,
            DZ_HAI => DZ_SHEN,
        ];

        return $config[$nz] ?? 12;
    }

    /**
     * 获取蜚廉
     *  根据出生年支
     * @param int $nz 出生年支
     * @return int
     */
    protected function getFeilian(int $nz): int
    {
        $config = [
            DZ_ZI => DZ_SHEN,
            DZ_CHOU => DZ_YOU,
            DZ_YIN => DZ_XU,
            DZ_MAO => DZ_SI,
            DZ_CHEN => DZ_WU,
            DZ_SI => DZ_WEI,
            DZ_WU => DZ_YIN,
            DZ_WEI => DZ_MAO,
            DZ_SHEN => DZ_CHEN,
            DZ_YOU => DZ_HAI,
            DZ_XU => DZ_ZI,
            DZ_HAI => DZ_CHOU,
        ];

        return $config[$nz] ?? 12;
    }

    /**
     * 获取台辅
     *  根据出生时支
     * @param int $sz 出生时支
     * @return int
     */
    protected function getTaifu(int $sz): int
    {
        $config = [
            DZ_ZI => DZ_WU,
            DZ_CHOU => DZ_WEI,
            DZ_YIN => DZ_SHEN,
            DZ_MAO => DZ_YOU,
            DZ_CHEN => DZ_XU,
            DZ_SI => DZ_HAI,
            DZ_WU => DZ_ZI,
            DZ_WEI => DZ_CHOU,
            DZ_SHEN => DZ_YIN,
            DZ_YOU => DZ_MAO,
            DZ_XU => DZ_CHEN,
            DZ_HAI => DZ_SI,
        ];

        return $config[$sz] ?? 12;
    }

    /**
     * 获取封诰
     *  根据出生时支
     * @param int $sz 出生时支
     * @return int
     */
    protected function getFenggao(int $sz): int
    {
        $config = [
            DZ_ZI => DZ_YIN,
            DZ_CHOU => DZ_MAO,
            DZ_YIN => DZ_CHEN,
            DZ_MAO => DZ_SI,
            DZ_CHEN => DZ_WU,
            DZ_SI => DZ_WEI,
            DZ_WU => DZ_SHEN,
            DZ_WEI => DZ_YOU,
            DZ_SHEN => DZ_XU,
            DZ_YOU => DZ_HAI,
            DZ_XU => DZ_ZI,
            DZ_HAI => DZ_CHOU,
        ];

        return $config[$sz] ?? 12;
    }

    /**
     * 获取天福
     *  根据出生年干
     * @param int $ng 出生年干
     * @return int
     */
    protected function getTianfu2(int $ng): int
    {
        $config = [
            TG_JIA => DZ_YOU,
            TG_YI => DZ_SHEN,
            TG_BING => DZ_ZI,
            TG_DING => DZ_HAI,
            TG_WU => DZ_MAO,
            TG_JI => DZ_YIN,
            TG_GENG => DZ_WU,
            TG_XIN => DZ_SI,
            TG_REN => DZ_WU,
            TG_GUI => DZ_SI,
        ];

        return $config[$ng] ?? 12;
    }

    /**
     * 获取天官
     *  根据出生年干
     * @param int $ng 出生年干
     * @return int
     */
    protected function getTianguan(int $ng): int
    {
        $config = [
            TG_JIA => DZ_WEI,
            TG_YI => DZ_CHEN,
            TG_BING => DZ_SI,
            TG_DING => DZ_YIN,
            TG_WU => DZ_MAO,
            TG_JI => DZ_YOU,
            TG_GENG => DZ_HAI,
            TG_XIN => DZ_YOU,
            TG_REN => DZ_XU,
            TG_GUI => DZ_WU,
        ];

        return $config[$ng] ?? 12;
    }

    /**
     * 获取截空（正空亡）
     *  根据出生年干
     * @param int $ng 出生年干
     * @return int
     */
    protected function getJiekong(int $ng): int
    {
        $config = [
            TG_JIA => DZ_SHEN,
            TG_YI => DZ_WEI,
            TG_BING => DZ_CHEN,
            TG_DING => DZ_MAO,
            TG_WU => DZ_ZI,
            TG_JI => DZ_YOU,
            TG_GENG => DZ_WU,
            TG_XIN => DZ_SI,
            TG_REN => DZ_YIN,
            TG_GUI => DZ_CHOU,
        ];

        return $config[$ng] ?? 12;
    }

    /**
     * 获取副截（副空亡）
     *  根据出生年干
     * @param int $ng 出生年干
     * @return int
     */
    protected function getFujie(int $ng): int
    {
        $config = [
            TG_JIA => DZ_YOU,
            TG_YI => DZ_WU,
            TG_BING => DZ_SI,
            TG_DING => DZ_YIN,
            TG_WU => DZ_CHOU,
            TG_JI => DZ_SHEN,
            TG_GENG => DZ_WEI,
            TG_XIN => DZ_CHEN,
            TG_REN => DZ_MAO,
            TG_GUI => DZ_ZI,
        ];

        return $config[$ng] ?? 12;
    }

    /**
     * 获取天厨
     *  根据出生年干
     *  巳午子巳午申寅午酉亥
     *      安天厨诀（年干）
     *  甲丁食蛇口，乙戊辛马方，丙从鼠口得
     *  己食于猴房，庚食虎疛上，壬鸡癸猪堂
     * @param int $ng 出生年干
     * @return int
     */
    protected function getTianchu(int $ng): int
    {
        $config = [
            TG_JIA => DZ_SI,
            TG_YI => DZ_WU,
            TG_BING => DZ_ZI,
            TG_DING => DZ_SI,
            TG_WU => DZ_WU,
            TG_JI => DZ_SHEN,
            TG_GENG => DZ_YIN,
            TG_XIN => DZ_WU,
            TG_REN => DZ_YOU,
            TG_GUI => DZ_HAI,
        ];

        return $config[$ng] ?? 12;
    }

    /**
     * 获取三台星位置
     *  由左辅星所在宫位上起初一日，顺时针数至出生日止，即在此宫安星
     * @param int $zuofu 左辅星所在宫
     * @param int $nlr 农历出生日
     * @return int
     */
    protected function getSantai(int $zuofu, int $nlr): int
    {
        return ($zuofu + $nlr - 1) % 12;
    }

    /**
     * 获取八座星位置
     *  由右弼星所在宫位上起初一日，逆时针数至出生日止，即在此宫安星
     * @param int $youbi 右弼星所在宫
     * @param int $nlr 农历出生日
     * @return int
     */
    protected function getBazuo(int $youbi, int $nlr): int
    {
        return $this->resetIndex(($youbi - $nlr + 1) % 12);
    }

    /**
     * 获取天贵星位置
     *  由文曲星所在宫位上起初一日，顺时针数至出生日止再退回一宫，即在此宫安星
     * @param int $wenqu 文曲星所在宫位
     * @param int $nlr 农历出生日
     * @return int
     */
    protected function getTiangui(int $wenqu, int $nlr): int
    {
        return $this->resetIndex(($wenqu + $nlr - 1 - 1) % 12);
    }

    /**
     * 获取恩光星位置
     *  由文昌星所在宫位上起初一日，顺时针数至出生日止再退回一宫，即在此宫安星
     * @param int $wenchang 文昌星所在宫位
     * @param int $nlr
     * @return int
     */
    protected function getEnguang(int $wenchang, int $nlr): int
    {
        return $this->resetIndex(($wenchang + $nlr - 1 - 1) % 12);
    }

    /**
     * 获取天才星
     *  由命宫起子年，顺时针数至出生年支所在宫止，即在此宫安星
     * @param int $minggong 命宫所在宫位
     * @param int $nz 出生年支
     * @return int
     */
    protected function getTiancai(int $minggong, int $nz): int
    {
        return ($minggong + $nz) % 12;
    }

    /**
     * 获取天寿星
     *  由身宫起子年，顺时针数至出生年支所在宫止，即在此宫安星
     * @param int $shengong 身宫所在宫位
     * @param int $nz 出生年支
     * @return int
     */
    protected function getTianshou(int $shengong, int $nz): int
    {
        return ($shengong + $nz) % 12;
    }

    /**
     * 天伤固定在奴仆宫
     * @param int $mg 命宫所在
     * @return int
     */
    protected function getTianshang(int $mg): int
    {
        return $this->resetIndex($mg - ZW_H8);
    }

    /**
     * 天使固定在疾厄宫
     * @param int $mg 身宫所在
     * @return int
     */
    protected function getTianshi(int $mg): int
    {
        return $this->resetIndex($mg - ZW_H6);
    }

    /**
     * 获取旬空
     * @param int $ng 出生年干
     * @param int $nz 出生年支
     * @return int
     */
    protected function getXunkong(int $ng, int $nz): int
    {
        $config = [
            TG_JIA => [
                DZ_ZI => DZ_XU,
                DZ_XU => DZ_SHEN,
                DZ_SHEN => DZ_WU,
                DZ_WU => DZ_CHEN,
                DZ_CHEN => DZ_YIN,
                DZ_YIN => DZ_ZI,
            ],
            TG_YI => [
                DZ_CHOU => DZ_HAI,
                DZ_HAI => DZ_YOU,
                DZ_YOU => DZ_WEI,
                DZ_WEI => DZ_SI,
                DZ_SI => DZ_MAO,
                DZ_MAO => DZ_CHOU,
            ],
            TG_BING => [
                DZ_YIN => DZ_XU,
                DZ_ZI => DZ_SHEN,
                DZ_XU => DZ_WU,
                DZ_SHEN => DZ_CHEN,
                DZ_WU => DZ_YIN,
                DZ_CHEN => DZ_ZI,
            ],
            TG_DING => [
                DZ_MAO => DZ_HAI,
                DZ_CHOU => DZ_YOU,
                DZ_HAI => DZ_WEI,
                DZ_YOU => DZ_SI,
                DZ_WEI => DZ_MAO,
                DZ_SI => DZ_CHOU,
            ],
            TG_WU => [
                DZ_CHEN => DZ_XU,
                DZ_YIN => DZ_SHEN,
                DZ_ZI => DZ_WU,
                DZ_XU => DZ_CHEN,
                DZ_SHEN => DZ_YIN,
                DZ_WU => DZ_ZI,
            ],
            TG_JI => [
                DZ_SI => DZ_HAI,
                DZ_MAO => DZ_YOU,
                DZ_CHOU => DZ_WEI,
                DZ_HAI => DZ_SI,
                DZ_YOU => DZ_MAO,
                DZ_WEI => DZ_CHOU,
            ],
            TG_GENG => [
                DZ_WU => DZ_XU,
                DZ_CHEN => DZ_SHEN,
                DZ_YIN => DZ_WU,
                DZ_ZI => DZ_CHEN,
                DZ_XU => DZ_YIN,
                DZ_SHEN => DZ_ZI,
            ],
            TG_XIN => [
                DZ_WEI => DZ_HAI,
                DZ_SI => DZ_YOU,
                DZ_MAO => DZ_WEI,
                DZ_CHOU => DZ_SI,
                DZ_HAI => DZ_MAO,
                DZ_YOU => DZ_CHOU,
            ],
            TG_REN => [
                DZ_SHEN => DZ_XU,
                DZ_WU => DZ_SHEN,
                DZ_CHEN => DZ_WU,
                DZ_YIN => DZ_CHEN,
                DZ_ZI => DZ_YIN,
                DZ_XU => DZ_ZI,
            ],
            TG_GUI => [
                DZ_YOU => DZ_HAI,
                DZ_WEI => DZ_YOU,
                DZ_SI => DZ_WEI,
                DZ_MAO => DZ_SI,
                DZ_CHOU => DZ_MAO,
                DZ_HAI => DZ_CHOU,
            ],
        ];

        return $config[$ng][$nz] ?? 12;
    }

    /**
     * 获取副旬
     * @param int $ng 出生年干
     * @param int $nz 出生年支
     * @return int
     */
    protected function getFuxun(int $ng, int $nz): int
    {
        $config = [
            TG_JIA => [
                DZ_ZI => DZ_HAI,
                DZ_XU => DZ_YOU,
                DZ_SHEN => DZ_WEI,
                DZ_WU => DZ_SI,
                DZ_CHEN => DZ_MAO,
                DZ_YIN => DZ_CHOU,
            ],
            TG_YI => [
                DZ_CHOU => DZ_XU,
                DZ_HAI => DZ_SHEN,
                DZ_YOU => DZ_WU,
                DZ_WEI => DZ_CHEN,
                DZ_SI => DZ_YIN,
                DZ_MAO => DZ_ZI,
            ],
            TG_BING => [
                DZ_YIN => DZ_HAI,
                DZ_ZI => DZ_YOU,
                DZ_XU => DZ_WEI,
                DZ_SHEN => DZ_SI,
                DZ_WU => DZ_MAO,
                DZ_CHEN => DZ_CHOU,
            ],
            TG_DING => [
                DZ_MAO => DZ_XU,
                DZ_CHOU => DZ_SHEN,
                DZ_HAI => DZ_WU,
                DZ_YOU => DZ_CHEN,
                DZ_WEI => DZ_YIN,
                DZ_SI => DZ_ZI,
            ],
            TG_WU => [
                DZ_CHEN => DZ_HAI,
                DZ_YIN => DZ_YOU,
                DZ_ZI => DZ_WEI,
                DZ_XU => DZ_SI,
                DZ_SHEN => DZ_MAO,
                DZ_WU => DZ_CHOU,
            ],
            TG_JI => [
                DZ_SI => DZ_XU,
                DZ_MAO => DZ_SHEN,
                DZ_CHOU => DZ_WU,
                DZ_HAI => DZ_CHEN,
                DZ_YOU => DZ_YIN,
                DZ_WEI => DZ_ZI,
            ],
            TG_GENG => [
                DZ_WU => DZ_HAI,
                DZ_CHEN => DZ_YOU,
                DZ_YIN => DZ_WEI,
                DZ_ZI => DZ_SI,
                DZ_XU => DZ_MAO,
                DZ_SHEN => DZ_CHOU,
            ],
            TG_XIN => [
                DZ_WEI => DZ_XU,
                DZ_SI => DZ_SHEN,
                DZ_MAO => DZ_WU,
                DZ_CHOU => DZ_CHEN,
                DZ_HAI => DZ_YIN,
                DZ_YOU => DZ_ZI,
            ],
            TG_REN => [
                DZ_SHEN => DZ_HAI,
                DZ_WU => DZ_YOU,
                DZ_CHEN => DZ_WEI,
                DZ_YIN => DZ_SI,
                DZ_ZI => DZ_MAO,
                DZ_XU => DZ_CHOU,
            ],
            TG_GUI => [
                DZ_YOU => DZ_XU,
                DZ_WEI => DZ_SHEN,
                DZ_SI => DZ_WU,
                DZ_MAO => DZ_CHEN,
                DZ_CHOU => DZ_YIN,
                DZ_HAI => DZ_ZI,
            ],
        ];

        return $config[$ng][$nz] ?? 12;
    }

    /**
     * 获取命主
     * @param int $mz 命宫地支
     * @return int
     */
    protected function getMingzhu(int $mz): int
    {
        $config = [ZW_TANLANG, ZW_JUMEN, ZW_LUCUN, ZW_WENQU, ZW_LIANZHEN, ZW_WUQU, ZW_POJUN, ZW_WUQU, ZW_LIANZHEN, ZW_WENQU, ZW_LUCUN, ZW_JUMEN];

        return $config[$mz] ?? 999;
    }

    /**
     * 获取身主
     * @param int $nz 出生年支
     * @return int
     */
    protected function getShenzhu(int $nz): int
    {
//        $config = [ZW_LINGXING, ZW_TIANXIANG, ZW_TIANLIANG, ZW_TIANTONG, ZW_WENCHANG, ZW_TIANJI, ZW_HUOXING, ZW_TIANXIANG, ZW_TIANLIANG, ZW_TIANTONG, ZW_WENCHANG, ZW_TIANJI];
        $config = [ZW_HUOXING, ZW_TIANXIANG, ZW_TIANLIANG, ZW_TIANTONG, ZW_WENCHANG, ZW_TIANJI, ZW_HUOXING, ZW_TIANXIANG, ZW_TIANLIANG, ZW_TIANTONG, ZW_WENCHANG, ZW_TIANJI];

        return $config[$nz] ?? 999;
    }

    /**
     * 获取博士十二神
     *  以禄存星所在宫开始，阳男阴女顺行，阴男阳女逆行，依次布下
     *  博士、力士、青龙、小耗、将军、奏书、飞廉、喜神、病符、大耗、伏兵、官符
     *  每一宫安一星
     * @param int $lucun 禄存星所在宫
     * @param int $z 宫位
     * @param string $yy 阳男｜阴女｜阴男｜阳女
     * @return int
     */
    protected function getBoshi(int $lucun, int $z, string $yy): int
    {
        if (in_array($yy, ['阳男', '阴女'], true))
        {
            $res = $z - $lucun;
        } else
        {
            $res = $lucun - $z;
        }
        return $this->resetIndex($res);
    }

    /**
     * 获取长生十二神
     *  长生落宫由五行局确定：金长生在巳、木长生在亥、火长生在寅、水土长生在申
     *  以长生宫开始，阳男阴女顺行，阴男阳女逆行，依次布下
     *  长生、沐浴、冠带、临官、帝旺、  衰、 病、  死、  墓、 绝、  胎、 养
     *  每一宫安一星
     * @param int $wxj 五行局 金木水火土
     * @param int $z 宫位
     * @param string $yy 阳男｜阴女｜阴男｜阳女
     * @return int
     */
    protected function getChangsheng(int $wxj, int $z, string $yy): int
    {
        $config = [DZ_SI, DZ_HAI, DZ_SHEN, DZ_YIN, DZ_SHEN];
        $res = $config[$wxj] ?? 0;
        if (in_array($yy, ['阳男', '阴女'], true))
        {
            // 顺行
            $res = $z - $res;
        } else
        {
            // 逆行
            $res -= $z;
        }
        return $this->resetIndex($res);
    }

    /**
     * 将前十二神
     *  查表得 将星、攀鞍、岁驿、息神、华盖、劫煞、灾煞、天煞、指背、咸池、月煞、亡神
     * @param int $nz 出生年支
     * @param int $z 宫位
     * @return int
     */
    protected function getJiangqian(int $nz, int $z): int
    {
        $config = [
            // 出生年支 => 宫 => 将前十二神
            DZ_ZI => [
                DZ_ZI => JQ_JIANGXING,
                DZ_CHOU => JQ_PANAN,
                DZ_YIN => JQ_SUIYI,
                DZ_MAO => JQ_XISHEN,
                DZ_CHEN => JQ_HUAGAI,
                DZ_SI => JQ_JIESHA,
                DZ_WU => JQ_ZAISHA,
                DZ_WEI => JQ_TIANSHA,
                DZ_SHEN => JQ_ZHIBEI,
                DZ_YOU => JQ_XIANCHI,
                DZ_XU => JQ_YUESHA,
                DZ_HAI => JQ_WANGSHEN,
            ],
            DZ_CHOU => [
                DZ_ZI => JQ_XISHEN,
                DZ_CHOU => JQ_HUAGAI,
                DZ_YIN => JQ_JIESHA,
                DZ_MAO => JQ_ZAISHA,
                DZ_CHEN => JQ_TIANSHA,
                DZ_SI => JQ_ZHIBEI,
                DZ_WU => JQ_XIANCHI,
                DZ_WEI => JQ_YUESHA,
                DZ_SHEN => JQ_WANGSHEN,
                DZ_YOU => JQ_JIANGXING,
                DZ_XU => JQ_PANAN,
                DZ_HAI => JQ_SUIYI,
            ],
            DZ_YIN => [
                DZ_ZI => JQ_ZAISHA,
                DZ_CHOU => JQ_TIANSHA,
                DZ_YIN => JQ_ZHIBEI,
                DZ_MAO => JQ_XIANCHI,
                DZ_CHEN => JQ_YUESHA,
                DZ_SI => JQ_WANGSHEN,
                DZ_WU => JQ_JIANGXING,
                DZ_WEI => JQ_PANAN,
                DZ_SHEN => JQ_SUIYI,
                DZ_YOU => JQ_XISHEN,
                DZ_XU => JQ_HUAGAI,
                DZ_HAI => JQ_JIESHA,
            ],
            DZ_MAO => [
                DZ_ZI => JQ_XIANCHI,
                DZ_CHOU => JQ_YUESHA,
                DZ_YIN => JQ_WANGSHEN,
                DZ_MAO => JQ_JIANGXING,
                DZ_CHEN => JQ_PANAN,
                DZ_SI => JQ_SUIYI,
                DZ_WU => JQ_XISHEN,
                DZ_WEI => JQ_HUAGAI,
                DZ_SHEN => JQ_JIESHA,
                DZ_YOU => JQ_ZAISHA,
                DZ_XU => JQ_TIANSHA,
                DZ_HAI => JQ_ZHIBEI,
            ],
            DZ_CHEN => [
                DZ_ZI => JQ_JIANGXING,
                DZ_CHOU => JQ_PANAN,
                DZ_YIN => JQ_SUIYI,
                DZ_MAO => JQ_XISHEN,
                DZ_CHEN => JQ_HUAGAI,
                DZ_SI => JQ_JIESHA,
                DZ_WU => JQ_ZAISHA,
                DZ_WEI => JQ_TIANSHA,
                DZ_SHEN => JQ_ZHIBEI,
                DZ_YOU => JQ_XIANCHI,
                DZ_XU => JQ_YUESHA,
                DZ_HAI => JQ_WANGSHEN,
            ],
            DZ_SI => [
                DZ_ZI => JQ_XISHEN,
                DZ_CHOU => JQ_HUAGAI,
                DZ_YIN => JQ_JIESHA,
                DZ_MAO => JQ_ZAISHA,
                DZ_CHEN => JQ_TIANSHA,
                DZ_SI => JQ_ZHIBEI,
                DZ_WU => JQ_XIANCHI,
                DZ_WEI => JQ_YUESHA,
                DZ_SHEN => JQ_WANGSHEN,
                DZ_YOU => JQ_JIANGXING,
                DZ_XU => JQ_PANAN,
                DZ_HAI => JQ_SUIYI,
            ],
            DZ_WU => [
                DZ_ZI => JQ_ZAISHA,
                DZ_CHOU => JQ_TIANSHA,
                DZ_YIN => JQ_ZHIBEI,
                DZ_MAO => JQ_XIANCHI,
                DZ_CHEN => JQ_YUESHA,
                DZ_SI => JQ_WANGSHEN,
                DZ_WU => JQ_JIANGXING,
                DZ_WEI => JQ_PANAN,
                DZ_SHEN => JQ_SUIYI,
                DZ_YOU => JQ_XISHEN,
                DZ_XU => JQ_HUAGAI,
                DZ_HAI => JQ_JIESHA,
            ],
            DZ_WEI => [
                DZ_ZI => JQ_XIANCHI,
                DZ_CHOU => JQ_YUESHA,
                DZ_YIN => JQ_WANGSHEN,
                DZ_MAO => JQ_JIANGXING,
                DZ_CHEN => JQ_PANAN,
                DZ_SI => JQ_SUIYI,
                DZ_WU => JQ_XISHEN,
                DZ_WEI => JQ_HUAGAI,
                DZ_SHEN => JQ_JIESHA,
                DZ_YOU => JQ_ZAISHA,
                DZ_XU => JQ_TIANSHA,
                DZ_HAI => JQ_ZHIBEI,
            ],
            DZ_SHEN => [
                DZ_ZI => JQ_JIANGXING,
                DZ_CHOU => JQ_PANAN,
                DZ_YIN => JQ_SUIYI,
                DZ_MAO => JQ_XISHEN,
                DZ_CHEN => JQ_HUAGAI,
                DZ_SI => JQ_JIESHA,
                DZ_WU => JQ_ZAISHA,
                DZ_WEI => JQ_TIANSHA,
                DZ_SHEN => JQ_ZHIBEI,
                DZ_YOU => JQ_XIANCHI,
                DZ_XU => JQ_YUESHA,
                DZ_HAI => JQ_WANGSHEN,
            ],
            DZ_YOU => [
                DZ_ZI => JQ_XISHEN,
                DZ_CHOU => JQ_HUAGAI,
                DZ_YIN => JQ_JIESHA,
                DZ_MAO => JQ_ZAISHA,
                DZ_CHEN => JQ_TIANSHA,
                DZ_SI => JQ_ZHIBEI,
                DZ_WU => JQ_XIANCHI,
                DZ_WEI => JQ_YUESHA,
                DZ_SHEN => JQ_WANGSHEN,
                DZ_YOU => JQ_JIANGXING,
                DZ_XU => JQ_PANAN,
                DZ_HAI => JQ_SUIYI,
            ],
            DZ_XU => [
                DZ_ZI => JQ_ZAISHA,
                DZ_CHOU => JQ_TIANSHA,
                DZ_YIN => JQ_ZHIBEI,
                DZ_MAO => JQ_XIANCHI,
                DZ_CHEN => JQ_YUESHA,
                DZ_SI => JQ_WANGSHEN,
                DZ_WU => JQ_JIANGXING,
                DZ_WEI => JQ_PANAN,
                DZ_SHEN => JQ_SUIYI,
                DZ_YOU => JQ_XISHEN,
                DZ_XU => JQ_HUAGAI,
                DZ_HAI => JQ_JIESHA,
            ],
            DZ_HAI => [
                DZ_ZI => JQ_XIANCHI,
                DZ_CHOU => JQ_YUESHA,
                DZ_YIN => JQ_WANGSHEN,
                DZ_MAO => JQ_JIANGXING,
                DZ_CHEN => JQ_PANAN,
                DZ_SI => JQ_SUIYI,
                DZ_WU => JQ_XISHEN,
                DZ_WEI => JQ_HUAGAI,
                DZ_SHEN => JQ_JIESHA,
                DZ_YOU => JQ_ZAISHA,
                DZ_XU => JQ_TIANSHA,
                DZ_HAI => JQ_ZHIBEI,
            ],
        ];

        return $config[$nz][$z] ?? 12;
    }

    /**
     * 太岁十二神
     *  查表得 岁建、晦气、丧门、贯索、官符、小耗、大耗、龙德、白虎、天德、吊客、病符
     * @param int $nz 出生年支
     * @param int $z 宫位
     * @return int
     */
    protected function getTaisui(int $nz, int $z): int
    {
        $config = [
            // 出生年支 => 宫 => 太岁十二神
            DZ_ZI => [
                DZ_ZI => TS_SUIJIAN,
                DZ_CHOU => TS_HUIQI,
                DZ_YIN => TS_SANGMEN,
                DZ_MAO => TS_GUANSUO,
                DZ_CHEN => TS_GUANFU,
                DZ_SI => TS_XIAOHAO,
                DZ_WU => TS_DAHAO,
                DZ_WEI => TS_LONGDE,
                DZ_SHEN => TS_BAIHU,
                DZ_YOU => TS_TIANDE,
                DZ_XU => TS_DIAOKE,
                DZ_HAI => TS_BINGFU,
            ],
            DZ_CHOU => [
                DZ_ZI => TS_BINGFU,
                DZ_CHOU => TS_SUIJIAN,
                DZ_YIN => TS_HUIQI,
                DZ_MAO => TS_SANGMEN,
                DZ_CHEN => TS_GUANSUO,
                DZ_SI => TS_GUANFU,
                DZ_WU => TS_XIAOHAO,
                DZ_WEI => TS_DAHAO,
                DZ_SHEN => TS_LONGDE,
                DZ_YOU => TS_BAIHU,
                DZ_XU => TS_TIANDE,
                DZ_HAI => TS_DIAOKE,
            ],
            DZ_YIN => [
                DZ_ZI => TS_DIAOKE,
                DZ_CHOU => TS_BINGFU,
                DZ_YIN => TS_SUIJIAN,
                DZ_MAO => TS_HUIQI,
                DZ_CHEN => TS_SANGMEN,
                DZ_SI => TS_GUANSUO,
                DZ_WU => TS_GUANFU,
                DZ_WEI => TS_XIAOHAO,
                DZ_SHEN => TS_DAHAO,
                DZ_YOU => TS_LONGDE,
                DZ_XU => TS_BAIHU,
                DZ_HAI => TS_TIANDE,
            ],
            DZ_MAO => [
                DZ_ZI => TS_TIANDE,
                DZ_CHOU => TS_DIAOKE,
                DZ_YIN => TS_BINGFU,
                DZ_MAO => TS_SUIJIAN,
                DZ_CHEN => TS_HUIQI,
                DZ_SI => TS_SANGMEN,
                DZ_WU => TS_GUANSUO,
                DZ_WEI => TS_GUANFU,
                DZ_SHEN => TS_XIAOHAO,
                DZ_YOU => TS_DAHAO,
                DZ_XU => TS_LONGDE,
                DZ_HAI => TS_BAIHU,
            ],
            DZ_CHEN => [
                DZ_ZI => TS_BAIHU,
                DZ_CHOU => TS_TIANDE,
                DZ_YIN => TS_DIAOKE,
                DZ_MAO => TS_BINGFU,
                DZ_CHEN => TS_SUIJIAN,
                DZ_SI => TS_HUIQI,
                DZ_WU => TS_SANGMEN,
                DZ_WEI => TS_GUANSUO,
                DZ_SHEN => TS_GUANFU,
                DZ_YOU => TS_XIAOHAO,
                DZ_XU => TS_DAHAO,
                DZ_HAI => TS_LONGDE,
            ],
            DZ_SI => [
                DZ_ZI => TS_LONGDE,
                DZ_CHOU => TS_BAIHU,
                DZ_YIN => TS_TIANDE,
                DZ_MAO => TS_DIAOKE,
                DZ_CHEN => TS_BINGFU,
                DZ_SI => TS_SUIJIAN,
                DZ_WU => TS_HUIQI,
                DZ_WEI => TS_SANGMEN,
                DZ_SHEN => TS_GUANSUO,
                DZ_YOU => TS_GUANFU,
                DZ_XU => TS_XIAOHAO,
                DZ_HAI => TS_DAHAO,
            ],
            DZ_WU => [
                DZ_ZI => TS_DAHAO,
                DZ_CHOU => TS_LONGDE,
                DZ_YIN => TS_BAIHU,
                DZ_MAO => TS_TIANDE,
                DZ_CHEN => TS_DIAOKE,
                DZ_SI => TS_BINGFU,
                DZ_WU => TS_SUIJIAN,
                DZ_WEI => TS_HUIQI,
                DZ_SHEN => TS_SANGMEN,
                DZ_YOU => TS_GUANSUO,
                DZ_XU => TS_GUANFU,
                DZ_HAI => TS_XIAOHAO,
            ],
            DZ_WEI => [
                DZ_ZI => TS_XIAOHAO,
                DZ_CHOU => TS_DAHAO,
                DZ_YIN => TS_LONGDE,
                DZ_MAO => TS_BAIHU,
                DZ_CHEN => TS_TIANDE,
                DZ_SI => TS_DIAOKE,
                DZ_WU => TS_BINGFU,
                DZ_WEI => TS_SUIJIAN,
                DZ_SHEN => TS_HUIQI,
                DZ_YOU => TS_SANGMEN,
                DZ_XU => TS_GUANSUO,
                DZ_HAI => TS_GUANFU,
            ],
            DZ_SHEN => [
                DZ_ZI => TS_GUANFU,
                DZ_CHOU => TS_XIAOHAO,
                DZ_YIN => TS_DAHAO,
                DZ_MAO => TS_LONGDE,
                DZ_CHEN => TS_BAIHU,
                DZ_SI => TS_TIANDE,
                DZ_WU => TS_DIAOKE,
                DZ_WEI => TS_BINGFU,
                DZ_SHEN => TS_SUIJIAN,
                DZ_YOU => TS_HUIQI,
                DZ_XU => TS_SANGMEN,
                DZ_HAI => TS_GUANSUO,
            ],
            DZ_YOU => [
                DZ_ZI => TS_GUANSUO,
                DZ_CHOU => TS_GUANFU,
                DZ_YIN => TS_XIAOHAO,
                DZ_MAO => TS_DAHAO,
                DZ_CHEN => TS_LONGDE,
                DZ_SI => TS_BAIHU,
                DZ_WU => TS_TIANDE,
                DZ_WEI => TS_DIAOKE,
                DZ_SHEN => TS_BINGFU,
                DZ_YOU => TS_SUIJIAN,
                DZ_XU => TS_HUIQI,
                DZ_HAI => TS_SANGMEN,
            ],
            DZ_XU => [
                DZ_ZI => TS_SANGMEN,
                DZ_CHOU => TS_GUANSUO,
                DZ_YIN => TS_GUANFU,
                DZ_MAO => TS_XIAOHAO,
                DZ_CHEN => TS_DAHAO,
                DZ_SI => TS_LONGDE,
                DZ_WU => TS_BAIHU,
                DZ_WEI => TS_TIANDE,
                DZ_SHEN => TS_DIAOKE,
                DZ_YOU => TS_BINGFU,
                DZ_XU => TS_SUIJIAN,
                DZ_HAI => TS_HUIQI,
            ],
            DZ_HAI => [
                DZ_ZI => TS_HUIQI,
                DZ_CHOU => TS_SANGMEN,
                DZ_YIN => TS_GUANSUO,
                DZ_MAO => TS_GUANFU,
                DZ_CHEN => TS_XIAOHAO,
                DZ_SI => TS_DAHAO,
                DZ_WU => TS_LONGDE,
                DZ_WEI => TS_BAIHU,
                DZ_SHEN => TS_TIANDE,
                DZ_YOU => TS_DIAOKE,
                DZ_XU => TS_BINGFU,
                DZ_HAI => TS_SUIJIAN,
            ],
        ];

        return $config[$nz][$z] ?? 12;
    }

    /**
     * 获取四化星(禄权科忌)
     *  甲廉破武阳（甲连破五羊）甲可以连续破五只羊的进攻；
     *  乙机梁紫阴（乙击两只鹰）乙可以击落两只老鹰；
     *  丙同机昌廉（兵同姬昌连）周文王姬昌之所以能胜利，是与士兵的心相连；
     *  丁阴同机巨（丁应同姬住）兵丁们应该可以与文王一起住；
     *  戊贪阴右机（勿贪淫又急）从不贪淫又急躁；
     *  己武贪梁曲（己舞弹两曲）高兴了自己跳支舞弹两支曲子；
     *  庚阳武阴同（供养五婴童）因为要供养五个小孩子；
     *  辛巨阳曲昌（幸拒养蛐唱）幸好拒绝了养蛐蛐唱歌；
     *  壬梁紫左武（松梁只作屋）松树的梁只能做屋子；
     *  癸破巨阴贪（鬼破主人叹）如果鬼把屋子弄破了主人只能叹息。
     * @param int $ng 出生年干
     * @return int[] 四化星耀的ID
     */
    protected function getSihua(int $ng): array
    {
        $config = [
            TG_JIA => [
                SH_LU => ZW_LIANZHEN,
                SH_QUAN => ZW_POJUN,
                SH_KE => $this->setting['sihua_jia'] ? ZW_WENQU : ZW_WUQU,
                SH_JI => ZW_TAIYANG,
            ],
            TG_YI => [
                SH_LU => ZW_TIANJI,
                SH_QUAN => ZW_TIANLIANG,
                SH_KE => ZW_ZIWEI,
                SH_JI => ZW_TAIYIN,
            ],
            TG_BING => [
                SH_LU => ZW_TIANTONG,
                SH_QUAN => ZW_TIANJI,
                SH_KE => ZW_WENCHANG,
                SH_JI => ZW_LIANZHEN,
            ],
            TG_DING => [
                SH_LU => ZW_TAIYIN,
                SH_QUAN => ZW_TIANTONG,
                SH_KE => ZW_TIANJI,
                SH_JI => ZW_JUMEN,
            ],
            TG_WU => [
                SH_LU => ZW_TANLANG,
                SH_QUAN => ZW_TAIYIN,
                SH_KE => $this->setting['sihua_jia'] ? ZW_TAIYANG : ZW_YOUBI,
                SH_JI => ZW_TIANJI,
            ],
            TG_JI => [
                SH_LU => ZW_WUQU,
                SH_QUAN => ZW_TANLANG,
                SH_KE => ZW_TIANLIANG,
                SH_JI => ZW_WENQU,
            ],
            TG_GENG => [
                SH_LU => ZW_TAIYANG,
                SH_QUAN => ZW_WUQU,
                SH_KE => $this->setting['sihua_jia'] ? ZW_TIANFU : ZW_TAIYIN,
                SH_JI => ZW_TIANTONG,
            ],
            TG_XIN => [
                SH_LU => ZW_JUMEN,
                SH_QUAN => ZW_TAIYANG,
                SH_KE => $this->setting['sihua_jia'] ? ZW_WUQU : ZW_WENQU,
                SH_JI => ZW_WENCHANG,
            ],
            TG_REN => [
                SH_LU => ZW_TIANLIANG,
                SH_QUAN => ZW_ZIWEI,
                SH_KE => $this->setting['sihua_jia'] ? ZW_TIANFU : ZW_ZUOFU,
                SH_JI => ZW_WUQU,
            ],
            TG_GUI => [
                SH_LU => ZW_POJUN,
                SH_QUAN => ZW_JUMEN,
                SH_KE => $this->setting['sihua_jia'] ? ZW_TAIYANG : ZW_TAIYIN,
                SH_JI => ZW_TANLANG,
            ],
        ];
        return $config[$ng];
    }

    /**
     * 获取星曜属性
     * @param int $x 星曜ID
     * @param int $g 宫位ID
     * @return string
     */
    protected function getXingShuxing(int $x, int $g): string
    {
        // 两位数，第一位表示阴阳，第二位表示五行，以-分隔多属性，例如 '01-12'
        // 第一位： 0=>阳, 1=>阴
        // 第二位： 0=>金, 1=> 木, 2=>水, 3=>火, 4=>土
        $config = [
            ZW_ZIWEI => '14', // 紫微(阴土)
            ZW_TIANJI => '11', // 天机(阴木)
            ZW_TAIYANG => '03', // 太阳(阳火)
            ZW_WUQU => '10', // 武曲(阴金)
            ZW_TIANTONG => '02', // 天同(阳水)
            ZW_LIANZHEN => '13-11-04', // 廉贞（丁干-阴火、乙干-阴木、戊干-阳土）
            ZW_TIANFU => '04', // 天府(阳土)
            ZW_TAIYIN => '12', // 太阴(阴水)
            ZW_TANLANG => '01-12', // 贪狼 （甲干-阳木、癸干-阴水）
            ZW_JUMEN => '12-14-10', // 巨门（癸干-阴水、己干-阴土、辛干-阴金）
            ZW_TIANXIANG => '02', // 天相(阳水)
            ZW_TIANLIANG => '04', // 天梁(阳土)
            ZW_QISHA => '00-13', // 七杀 （庚干-阳金、丁干-阴火）
            ZW_POJUN => '12-10', // 破军 （癸干-阴水、辛干-阴金）

            ZW_WENCHANG => '00', // 文昌(阳金)
            ZW_WENQU => '12', // 文曲(阴水)
            ZW_ZUOFU => '04', // 左辅(阳土)
            ZW_YOUBI => '12', // 右弼(阴水)
            ZW_TIANKUI => '03', // 天魁  阳火
            ZW_TIANYUE => '13', // 天钺  阴火
            ZW_LUCUN => '14', // 禄存(阴土)
            ZW_TIANMA => '03', // 天马(阳火)

            ZW_QINGYANG => '00-03', // 擎羊(阳金、阳火)
            ZW_TUOLUO => '10', // 陀罗(阴金)
            ZW_HUOXING => '03', // 火星(阳火)
            ZW_LINGXING => '13', // 铃星(阴火)
            ZW_DIKONG => '13', // 地空(阴火)
            ZW_DIJIE => '03', // 地劫(阳火)
        ];
        return $config[$x];
    }

    /**
     * 获取属性文案
     * @param string $attr
     * @return string
     */
    protected function getXingShuxingText(string $attr): string
    {
        $res = '';
        $arr = explode('-', $attr);
        if (!empty($arr))
        {
            $count = count($arr);
            foreach ($arr as $k => $v)
            {
                $yyNum = (int)substr($v, 0, 1);
                $wxNum = (int)substr($v, 1, 1);
                $res .= $yyNum ? '阴' : '阳';
                $res .= $this->getWuxingText($wxNum);
                if ($k < $count - 1)
                {
                    $res .= '/';
                }
            }
        }
        return $res;
    }

    /**
     *  获取主星庙旺失陷
     *  （中州派分为庙旺平闲陷五级）
     * @param int $x 主星名称，例如：紫微
     * @param int $g 主星所在宫位，例如：子
     * @return int
     */
    protected function getDefen(int $x, int $g): ?int
    {
        // 庙+2、旺+1、平0、闲-1、陷-2
        $config = [
            ZW_ZIWEI => [
                DZ_ZI => 0,
                DZ_CHOU => 2,
                DZ_YIN => 2,
                DZ_MAO => 1,
                DZ_CHEN => -2,
                DZ_SI => 1,
                DZ_WU => 2,
                DZ_WEI => 2,
                DZ_SHEN => 1,
                DZ_YOU => 0,
                DZ_XU => -1,
                DZ_HAI => 1,
            ],
            ZW_TIANJI => [
                DZ_ZI => 2,
                DZ_CHOU => -2,
                DZ_YIN => 1,
                DZ_MAO => 1,
                DZ_CHEN => 2,
                DZ_SI => 0,
                DZ_WU => 2,
                DZ_WEI => -2,
                DZ_SHEN => 0,
                DZ_YOU => 1,
                DZ_XU => 2,
                DZ_HAI => 0,
            ],
            ZW_TAIYANG => [
                DZ_ZI => -2,
                DZ_CHOU => -2,
                DZ_YIN => 1,
                DZ_MAO => 2,
                DZ_CHEN => 1,
                DZ_SI => 1,
                DZ_WU => 2,
                DZ_WEI => 0,
                DZ_SHEN => -1,
                DZ_YOU => -1,
                DZ_XU => -2,
                DZ_HAI => -2,
            ],
            ZW_WUQU => [
                DZ_ZI => 1,
                DZ_CHOU => 2,
                DZ_YIN => -1,
                DZ_MAO => -2,
                DZ_CHEN => 2,
                DZ_SI => 0,
                DZ_WU => 1,
                DZ_WEI => 2,
                DZ_SHEN => 0,
                DZ_YOU => 1,
                DZ_XU => 2,
                DZ_HAI => 0,
            ],
            ZW_TIANTONG => [
                DZ_ZI => 1,
                DZ_CHOU => -2,
                DZ_YIN => -1,
                DZ_MAO => 2,
                DZ_CHEN => 0,
                DZ_SI => 2,
                DZ_WU => -2,
                DZ_WEI => -2,
                DZ_SHEN => 1,
                DZ_YOU => 0,
                DZ_XU => 0,
                DZ_HAI => 2,
            ],
            ZW_LIANZHEN => [
                DZ_ZI => 0,
                DZ_CHOU => 1,
                DZ_YIN => 2,
                DZ_MAO => -1,
                DZ_CHEN => 1,
                DZ_SI => -2,
                DZ_WU => 0,
                DZ_WEI => 2,
                DZ_SHEN => 2,
                DZ_YOU => 0,
                DZ_XU => 1,
                DZ_HAI => -2,
            ],
            ZW_TIANFU => [
                DZ_ZI => 2,
                DZ_CHOU => 2,
                DZ_YIN => 2,
                DZ_MAO => 0,
                DZ_CHEN => 2,
                DZ_SI => 0,
                DZ_WU => 1,
                DZ_WEI => 2,
                DZ_SHEN => 0,
                DZ_YOU => -2,
                DZ_XU => 2,
                DZ_HAI => 1,
            ],
            ZW_TAIYIN => [
                DZ_ZI => 2,
                DZ_CHOU => 2,
                DZ_YIN => -1,
                DZ_MAO => -2,
                DZ_CHEN => 2,
                DZ_SI => -2,
                DZ_WU => -2,
                DZ_WEI => 0,
                DZ_SHEN => 0,
                DZ_YOU => 1,
                DZ_XU => 1,
                DZ_HAI => 2,
            ],
            ZW_TANLANG => [
                DZ_ZI => 1,
                DZ_CHOU => 2,
                DZ_YIN => 0,
                DZ_MAO => -1,
                DZ_CHEN => 2,
                DZ_SI => -2,
                DZ_WU => 1,
                DZ_WEI => 2,
                DZ_SHEN => 2,
                DZ_YOU => 0,
                DZ_XU => 2,
                DZ_HAI => -2,
            ],
            ZW_JUMEN => [
                DZ_ZI => 1,
                DZ_CHOU => 1,
                DZ_YIN => 2,
                DZ_MAO => 2,
                DZ_CHEN => 0,
                DZ_SI => 0,
                DZ_WU => 1,
                DZ_WEI => -2,
                DZ_SHEN => 2,
                DZ_YOU => 2,
                DZ_XU => 1,
                DZ_HAI => 1,
            ],
            ZW_TIANXIANG => [
                DZ_ZI => 2,
                DZ_CHOU => 2,
                DZ_YIN => 2,
                DZ_MAO => -2,
                DZ_CHEN => 1,
                DZ_SI => 0,
                DZ_WU => 1,
                DZ_WEI => -1,
                DZ_SHEN => 2,
                DZ_YOU => -2,
                DZ_XU => -1,
                DZ_HAI => 0,
            ],
            ZW_TIANLIANG => [
                DZ_ZI => 2,
                DZ_CHOU => 1,
                DZ_YIN => 2,
                DZ_MAO => 2,
                DZ_CHEN => 1,
                DZ_SI => -2,
                DZ_WU => 2,
                DZ_WEI => 1,
                DZ_SHEN => -2,
                DZ_YOU => -1,
                DZ_XU => 1,
                DZ_HAI => -2,
            ],
            ZW_QISHA => [
                DZ_ZI => 1,
                DZ_CHOU => 2,
                DZ_YIN => 2,
                DZ_MAO => -2,
                DZ_CHEN => 1,
                DZ_SI => 0,
                DZ_WU => 1,
                DZ_WEI => 1,
                DZ_SHEN => 2,
                DZ_YOU => -1,
                DZ_XU => 2,
                DZ_HAI => 0,
            ],
            ZW_POJUN => [
                DZ_ZI => 2,
                DZ_CHOU => 1,
                DZ_YIN => -2,
                DZ_MAO => 1,
                DZ_CHEN => 1,
                DZ_SI => -1,
                DZ_WU => 2,
                DZ_WEI => 2,
                DZ_SHEN => -2,
                DZ_YOU => -2,
                DZ_XU => 1,
                DZ_HAI => 0,
            ],
            ZW_HUOXING => [
                DZ_ZI => 0,
                DZ_CHOU => 1,
                DZ_YIN => 2,
                DZ_MAO => 0,
                DZ_CHEN => -1,
                DZ_SI => 1,
                DZ_WU => 2,
                DZ_WEI => -1,
                DZ_SHEN => -2,
                DZ_YOU => -2,
                DZ_XU => 2,
                DZ_HAI => 0,
            ],
            ZW_LINGXING => [
                DZ_ZI => -2,
                DZ_CHOU => -2,
                DZ_YIN => 2,
                DZ_MAO => null,
                DZ_CHEN => 1,
                DZ_SI => 1,
                DZ_WU => 2,
                DZ_WEI => 1,
                DZ_SHEN => 1,
                DZ_YOU => -2,
                DZ_XU => 2,
                DZ_HAI => 2,
            ],
            ZW_QINGYANG => [
                DZ_ZI => -2,
                DZ_CHOU => 2,
                DZ_YIN => null,
                DZ_MAO => -2,
                DZ_CHEN => 2,
                DZ_SI => null,
                DZ_WU => 0,
                DZ_WEI => 2,
                DZ_SHEN => null,
                DZ_YOU => -2,
                DZ_XU => 2,
                DZ_HAI => null,
            ],
            ZW_TUOLUO => [
                DZ_ZI => null,
                DZ_CHOU => 2,
                DZ_YIN => -2,
                DZ_MAO => null,
                DZ_CHEN => 2,
                DZ_SI => -2,
                DZ_WU => null,
                DZ_WEI => 2,
                DZ_SHEN => -2,
                DZ_YOU => null,
                DZ_XU => 2,
                DZ_HAI => -2,
            ],
            ZW_WENCHANG => [
                DZ_ZI => 1,
                DZ_CHOU => 2,
                DZ_YIN => -2,
                DZ_MAO => 0,
                DZ_CHEN => 1,
                DZ_SI => -2,
                DZ_WU => 2,
                DZ_WEI => 0,
                DZ_SHEN => 1,
                DZ_YOU => 2,
                DZ_XU => -2,
                DZ_HAI => 1,
            ],
            ZW_WENQU => [
                DZ_ZI => 2,
                DZ_CHOU => 2,
                DZ_YIN => 0,
                DZ_MAO => 1,
                DZ_CHEN => 2,
                DZ_SI => 2,
                DZ_WU => -2,
                DZ_WEI => 1,
                DZ_SHEN => 0,
                DZ_YOU => 2,
                DZ_XU => -2,
                DZ_HAI => 1,
            ],
            ZW_TIANKUI => [
                DZ_ZI => 1,
                DZ_CHOU => 1,
                DZ_YIN => null,
                DZ_MAO => 2,
                DZ_CHEN => null,
                DZ_SI => null,
                DZ_WU => 2,
                DZ_WEI => null,
                DZ_SHEN => null,
                DZ_YOU => null,
                DZ_XU => null,
                DZ_HAI => 1,
            ],
            ZW_TIANYUE => [
                DZ_ZI => null,
                DZ_CHOU => null,
                DZ_YIN => 1,
                DZ_MAO => null,
                DZ_CHEN => null,
                DZ_SI => 1,
                DZ_WU => null,
                DZ_WEI => 1,
                DZ_SHEN => 2,
                DZ_YOU => 2,
                DZ_XU => null,
                DZ_HAI => null,
            ],
            ZW_ZUOFU => [
                DZ_ZI => 1,
                DZ_CHOU => 2,
                DZ_YIN => 2,
                DZ_MAO => -2,
                DZ_CHEN => 2,
                DZ_SI => 0,
                DZ_WU => 1,
                DZ_WEI => 2,
                DZ_SHEN => 0,
                DZ_YOU => -2,
                DZ_XU => 2,
                DZ_HAI => -1,
            ],
            ZW_YOUBI => [
                DZ_ZI => 2,
                DZ_CHOU => 2,
                DZ_YIN => 1,
                DZ_MAO => -2,
                DZ_CHEN => 2,
                DZ_SI => 0,
                DZ_WU => 1,
                DZ_WEI => 2,
                DZ_SHEN => -1,
                DZ_YOU => -2,
                DZ_XU => 2,
                DZ_HAI => 0,
            ],
            ZW_LUCUN => [
                DZ_ZI => 1,
                DZ_CHOU => null,
                DZ_YIN => 2,
                DZ_MAO => 1,
                DZ_CHEN => null,
                DZ_SI => 2,
                DZ_WU => 1,
                DZ_WEI => null,
                DZ_SHEN => 2,
                DZ_YOU => 1,
                DZ_XU => null,
                DZ_HAI => 2,
            ],
            ZW_TIANMA => [
                DZ_ZI => null,
                DZ_CHOU => null,
                DZ_YIN => 1,
                DZ_MAO => null,
                DZ_CHEN => null,
                DZ_SI => 0,
                DZ_WU => null,
                DZ_WEI => null,
                DZ_SHEN => 1,
                DZ_YOU => null,
                DZ_XU => null,
                DZ_HAI => 0,
            ],
            ZW_DIKONG => [
                DZ_ZI => 0,
                DZ_CHOU => -2,
                DZ_YIN => -2,
                DZ_MAO => 0,
                DZ_CHEN => -2,
                DZ_SI => 2,
                DZ_WU => 2,
                DZ_WEI => 0,
                DZ_SHEN => 2,
                DZ_YOU => 2,
                DZ_XU => -2,
                DZ_HAI => -2,
            ],
            ZW_DIJIE => [
                DZ_ZI => -2,
                DZ_CHOU => -2,
                DZ_YIN => 0,
                DZ_MAO => 0,
                DZ_CHEN => -2,
                DZ_SI => -1,
                DZ_WU => 2,
                DZ_WEI => 0,
                DZ_SHEN => 2,
                DZ_YOU => 0,
                DZ_XU => 0,
                DZ_HAI => 1,
            ],
        ];
        return $config[$x][$g] ?? -10;
    }

    /**
     *  获取主星庙旺失陷
     *  （来源：紫微斗数全书）
     * @param int $x 主星名称，例如：0=>紫微
     * @param int $g 主星所在宫位，例如：0=>子
     * @return int
     */
    protected function getDefen2(int $x, int $g): ?int
    {

        // 庙+3、旺+2、得地+1、利益0、平和-1、不得地-2、落陷-3
        $config = [
            // 紫微
            ZW_ZIWEI => [
                DZ_ZI => -1,
                DZ_CHOU => 3,
                DZ_YIN => 2,
                DZ_MAO => 2,
                DZ_CHEN => 1,
                DZ_SI => 2,
                DZ_WU => 3,
                DZ_WEI => 3,
                DZ_SHEN => 2,
                DZ_YOU => 2,
                DZ_XU => 1,
                DZ_HAI => 2,
            ],
            // 天机
            ZW_TIANJI => [
                DZ_ZI => 3,
                DZ_CHOU => -3,
                DZ_YIN => 1,
                DZ_MAO => 2,
                DZ_CHEN => 0,
                DZ_SI => -1,
                DZ_WU => 3,
                DZ_WEI => -3,
                DZ_SHEN => 1,
                DZ_YOU => 2,
                DZ_XU => 0,
                DZ_HAI => -1,
            ],
            // 太阳
            ZW_TAIYANG => [
                DZ_ZI => -3,
                DZ_CHOU => -2,
                DZ_YIN => 2,
                DZ_MAO => 3,
                DZ_CHEN => 2,
                DZ_SI => 2,
                DZ_WU => 2,
                DZ_WEI => 1,
                DZ_SHEN => 0,
                DZ_YOU => -1,
                DZ_XU => -2,
                DZ_HAI => -3,
            ],
            // 武曲
            ZW_WUQU => [
                DZ_ZI => 2,
                DZ_CHOU => 3,
                DZ_YIN => 1,
                DZ_MAO => 0,
                DZ_CHEN => 3,
                DZ_SI => -1,
                DZ_WU => 2,
                DZ_WEI => 3,
                DZ_SHEN => 1,
                DZ_YOU => 0,
                DZ_XU => 3,
                DZ_HAI => -1,
            ],
            // 天同
            ZW_TIANTONG => [
                DZ_ZI => 2,
                DZ_CHOU => -2,
                DZ_YIN => 0,
                DZ_MAO => -1,
                DZ_CHEN => -1,
                DZ_SI => 3,
                DZ_WU => -3,
                DZ_WEI => -2,
                DZ_SHEN => 2,
                DZ_YOU => -1,
                DZ_XU => -1,
                DZ_HAI => 3,
            ],
            // 廉贞
            ZW_LIANZHEN => [
                DZ_ZI => -1,
                DZ_CHOU => 0,
                DZ_YIN => 3,
                DZ_MAO => -1,
                DZ_CHEN => 0,
                DZ_SI => -3,
                DZ_WU => -1,
                DZ_WEI => 0,
                DZ_SHEN => 3,
                DZ_YOU => -1,
                DZ_XU => 0,
                DZ_HAI => -3,
            ],
            // 天府
            ZW_TIANFU => [
                DZ_ZI => 3,
                DZ_CHOU => 3,
                DZ_YIN => 3,
                DZ_MAO => 1,
                DZ_CHEN => 3,
                DZ_SI => 1,
                DZ_WU => 2,
                DZ_WEI => 3,
                DZ_SHEN => 1,
                DZ_YOU => 2,
                DZ_XU => 3,
                DZ_HAI => 1,
            ],
            // 太阴
            ZW_TAIYIN => [
                DZ_ZI => 3,
                DZ_CHOU => 3,
                DZ_YIN => 1,
                DZ_MAO => -3,
                DZ_CHEN => -3,
                DZ_SI => -3,
                DZ_WU => -2,
                DZ_WEI => -2,
                DZ_SHEN => 0,
                DZ_YOU => 2,
                DZ_XU => 2,
                DZ_HAI => 3,
            ],
            // 贪狼
            ZW_TANLANG => [
                DZ_ZI => 2,
                DZ_CHOU => 3,
                DZ_YIN => -1,
                DZ_MAO => 0,
                DZ_CHEN => 3,
                DZ_SI => -3,
                DZ_WU => 2,
                DZ_WEI => 3,
                DZ_SHEN => -1,
                DZ_YOU => 0,
                DZ_XU => 3,
                DZ_HAI => -3,
            ],
            // 巨门
            ZW_JUMEN => [
                DZ_ZI => 2,
                DZ_CHOU => -2,
                DZ_YIN => 3,
                DZ_MAO => 3,
                DZ_CHEN => -3,
                DZ_SI => 2,
                DZ_WU => 2,
                DZ_WEI => -2,
                DZ_SHEN => 3,
                DZ_YOU => 3,
                DZ_XU => -3,
                DZ_HAI => 2,
            ],
            // 天相
            ZW_TIANXIANG => [
                DZ_ZI => 3,
                DZ_CHOU => 3,
                DZ_YIN => 3,
                DZ_MAO => -3,
                DZ_CHEN => 1,
                DZ_SI => 1,
                DZ_WU => 3,
                DZ_WEI => 1,
                DZ_SHEN => 3,
                DZ_YOU => -3,
                DZ_XU => 1,
                DZ_HAI => 1,
            ],
            // 天梁
            ZW_TIANLIANG => [
                DZ_ZI => 3,
                DZ_CHOU => 2,
                DZ_YIN => 3,
                DZ_MAO => 3,
                DZ_CHEN => 3,
                DZ_SI => 1,
                DZ_WU => 3,
                DZ_WEI => 2,
                DZ_SHEN => -3,
                DZ_YOU => 1,
                DZ_XU => 3,
                DZ_HAI => -3,
            ],
            // 七杀
            ZW_QISHA => [
                DZ_ZI => 2,
                DZ_CHOU => 3,
                DZ_YIN => 3,
                DZ_MAO => 2,
                DZ_CHEN => 3,
                DZ_SI => -1,
                DZ_WU => 2,
                DZ_WEI => 3,
                DZ_SHEN => 3,
                DZ_YOU => 2,
                DZ_XU => 3,
                DZ_HAI => -1,
            ],
            // 破军
            ZW_POJUN => [
                DZ_ZI => 3,
                DZ_CHOU => 2,
                DZ_YIN => 1,
                DZ_MAO => -3,
                DZ_CHEN => 2,
                DZ_SI => -1,
                DZ_WU => 3,
                DZ_WEI => 2,
                DZ_SHEN => 1,
                DZ_YOU => -3,
                DZ_XU => 2,
                DZ_HAI => -1,
            ],
            // 文昌
            ZW_WENCHANG => [
                DZ_ZI => 1,
                DZ_CHOU => 3,
                DZ_YIN => -3,
                DZ_MAO => 2,
                DZ_CHEN => 1,
                DZ_SI => 3,
                DZ_WU => -3,
                DZ_WEI => 0,
                DZ_SHEN => 1,
                DZ_YOU => 3,
                DZ_XU => -3,
                DZ_HAI => 0,
            ],
            // 文曲
            ZW_WENQU => [
                DZ_ZI => 3,
                DZ_CHOU => 3,
                DZ_YIN => -1,
                DZ_MAO => 0,
                DZ_CHEN => 1,
                DZ_SI => 3,
                DZ_WU => -3,
                DZ_WEI => 2,
                DZ_SHEN => 1,
                DZ_YOU => 3,
                DZ_XU => -3,
                DZ_HAI => 2,
            ],
            // 左辅
            ZW_ZUOFU => [
                DZ_ZI => 2,
                DZ_CHOU => 3,
                DZ_YIN => 3,
                DZ_MAO => -3,
                DZ_CHEN => 3,
                DZ_SI => -1,
                DZ_WU => 2,
                DZ_WEI => 3,
                DZ_SHEN => -1,
                DZ_YOU => -3,
                DZ_XU => 3,
                DZ_HAI => -2,
            ],
            // 右弼
            ZW_YOUBI => [
                DZ_ZI => 3,
                DZ_CHOU => 3,
                DZ_YIN => 2,
                DZ_MAO => -3,
                DZ_CHEN => 3,
                DZ_SI => -1,
                DZ_WU => 2,
                DZ_WEI => 3,
                DZ_SHEN => -2,
                DZ_YOU => -3,
                DZ_XU => 3,
                DZ_HAI => -1,
            ],
            // 天魁
            ZW_TIANKUI => [
                DZ_ZI => 2,
                DZ_CHOU => 2,
                DZ_YIN => null,
                DZ_MAO => 3,
                DZ_CHEN => null,
                DZ_SI => null,
                DZ_WU => null,
                DZ_WEI => null,
                DZ_SHEN => null,
                DZ_YOU => null,
                DZ_XU => null,
                DZ_HAI => 2,
            ],
            // 天钺
            ZW_TIANYUE => [
                DZ_ZI => null,
                DZ_CHOU => null,
                DZ_YIN => null,
                DZ_MAO => null,
                DZ_CHEN => null,
                DZ_SI => 2,
                DZ_WU => null,
                DZ_WEI => 2,
                DZ_SHEN => 3,
                DZ_YOU => 3,
                DZ_XU => null,
                DZ_HAI => null,
            ],
            // 禄存
            ZW_LUCUN => [
                DZ_ZI => 3,
                DZ_CHOU => null,
                DZ_YIN => 3,
                DZ_MAO => 3,
                DZ_CHEN => null,
                DZ_SI => 3,
                DZ_WU => 3,
                DZ_WEI => null,
                DZ_SHEN => 3,
                DZ_YOU => 3,
                DZ_XU => null,
                DZ_HAI => 3,
            ],
            // 天马
            ZW_TIANMA => [
                DZ_ZI => null,
                DZ_CHOU => null,
                DZ_YIN => 2,
                DZ_MAO => null,
                DZ_CHEN => null,
                DZ_SI => -1,
                DZ_WU => null,
                DZ_WEI => null,
                DZ_SHEN => 2,
                DZ_YOU => null,
                DZ_XU => null,
                DZ_HAI => -1,
            ],
            // 擎羊
            ZW_QINGYANG => [
                DZ_ZI => -3,
                DZ_CHOU => 3,
                DZ_YIN => null,
                DZ_MAO => -3,
                DZ_CHEN => 3,
                DZ_SI => null,
                DZ_WU => -3,
                DZ_WEI => 3,
                DZ_SHEN => null,
                DZ_YOU => -3,
                DZ_XU => 3,
                DZ_HAI => null,
            ],
            // 陀罗
            ZW_TUOLUO => [
                DZ_ZI => null,
                DZ_CHOU => 3,
                DZ_YIN => -3,
                DZ_MAO => -3,
                DZ_CHEN => 3,
                DZ_SI => -3,
                DZ_WU => null,
                DZ_WEI => 3,
                DZ_SHEN => -3,
                DZ_YOU => null,
                DZ_XU => 3,
                DZ_HAI => -3,
            ],
            // 火星
            ZW_HUOXING => [
                DZ_ZI => -3,
                DZ_CHOU => 1,
                DZ_YIN => 3,
                DZ_MAO => 0,
                DZ_CHEN => -3,
                DZ_SI => 1,
                DZ_WU => 3,
                DZ_WEI => 0,
                DZ_SHEN => -3,
                DZ_YOU => 1,
                DZ_XU => 3,
                DZ_HAI => 0,
            ],
            // 铃星
            ZW_LINGXING => [
                DZ_ZI => -3,
                DZ_CHOU => 1,
                DZ_YIN => 3,
                DZ_MAO => 0,
                DZ_CHEN => -3,
                DZ_SI => 1,
                DZ_WU => 3,
                DZ_WEI => 0,
                DZ_SHEN => -3,
                DZ_YOU => 1,
                DZ_XU => 3,
                DZ_HAI => 0,
            ],
            // 地空
            ZW_DIKONG => [
                DZ_ZI => -1,
                DZ_CHOU => -3,
                DZ_YIN => -3,
                DZ_MAO => -1,
                DZ_CHEN => -3,
                DZ_SI => 3,
                DZ_WU => 3,
                DZ_WEI => -1,
                DZ_SHEN => 3,
                DZ_YOU => 3,
                DZ_XU => -3,
                DZ_HAI => -3,
            ],
            // 地劫
            ZW_DIJIE => [
                DZ_ZI => -3,
                DZ_CHOU => -3,
                DZ_YIN => -1,
                DZ_MAO => -1,
                DZ_CHEN => -3,
                DZ_SI => -2,
                DZ_WU => 3,
                DZ_WEI => -1,
                DZ_SHEN => 3,
                DZ_YOU => -1,
                DZ_XU => -1,
                DZ_HAI => null,
            ]
        ];
        return $config[$x][$g] ?? -10;
    }

    /**
     * 子年斗君（生月，生时）
     *  太岁宫中便起正，逆回数至生月停
     *  此宫顺流子时位，流至生时安斗君
     *  （例如：五月卯时生人，算他的子年斗君，于子宫起一月逆行，亥宫二月...，申宫五月，于申宫起子时顺回，酉宫丑时，戌宫寅时，亥宫卯时，得子年斗君在亥。得子年斗君宫位后，便可依次推算出每年斗君，如丑年斗君在子，寅年斗君在丑等等。）
     *  （例如：三月辰时生人，算乙酉年的斗君，则于酉宫起正月，逆数申宫位二月，未宫三月，于未宫起子时，顺数申宫为丑时，酉宫为寅时，戌宫为卯时，亥宫为辰时，得流年斗君为亥。）
     * @param int $nly 农历月：3 [1, 12]
     * @param int $sz 时支：4 [0, 11]
     * @return int
     */
    protected function getZinianDoujun(int $nly, int $sz): int
    {
        $res = 0;
        // 起一月逆行至生月
        $res -= ($nly - 1);
        // 起子时顺行至生时
        $res += $sz;

        return $this->resetIndex($res, 0, 11);
    }

    /**
     * 流年斗君（生月，生时，流年地支）
     *  太岁宫中便起正，逆回数至生月停
     *  此宫顺流子时位，流至生时安斗君
     *  （例如：五月卯时生人，算他的子年斗君，于子宫起一月逆行，亥宫二月...，申宫五月，于申宫起子时顺回，酉宫丑时，戌宫寅时，亥宫卯时，得子年斗君在亥。得子年斗君宫位后，便可依次推算出每年斗君，如丑年斗君在子，寅年斗君在丑等等。）
     *  （例如：三月辰时生人，算乙酉年的斗君，则于酉宫起正月，逆数申宫位二月，未宫三月，于未宫起子时，顺数申宫为丑时，酉宫为寅时，戌宫为卯时，亥宫为辰时，得流年斗君为亥。）
     * @param int $nly 农历月：3 [1, 12]
     * @param int $sz 时支：4 [0, 11]
     * @param int $lnz 年支：9 [0, 11]
     * @return int
     */
    protected function getLiunianDoujun(int $nly, int $sz, int $lnz): int
    {
        $res = $lnz;
        // 起一月逆行至生月
        $res -= ($nly - 1);
        // 起子时顺行至生时
        $res += $sz;

        return $this->resetIndex($res, 0, 11);
    }

    /**
     * 获取档案的阴阳属性
     * @param int $value [0, 1]
     * @return string
     */
    protected function getYinyangText(int $value): string
    {
        $config = ['阳', '阴'];
        return $config[$value];
    }

    /**
     * 计算星耀位置
     * @param int $xid
     * @param array $option
     *  zwg int 紫微所在宫位
     *  wxj int 五行局
     *  ngs int 年干
     *  nzs int 年支
     *  szs int 时支
     *  nly int 农历出生月
     *  nlr int 农历出生日
     *  mgz int 命宫所在
     *  sgz int 身宫所在
     * @return int
     */
    protected function getXingyao(int $xid, array $option)
    {
        switch ($xid)
        {
            case ZW_ZIWEI:
                $res = $option['zwg']; // 紫微
                break;
            case ZW_TIANJI:
                $res = $this->getTianji($option['zwg']); // 天机
                break;
            case ZW_TAIYANG:
                $res = $this->getTaiyang($option['zwg']); // 太阳
                break;
            case ZW_WUQU:
                $res = $this->getWuqu($option['zwg']); // 武曲
                break;
            case ZW_TIANTONG:
                $res = $this->getTiantong($option['zwg']); // 天同
                break;
            case ZW_LIANZHEN:
                $res = $this->getLianzhen($option['zwg']); // 廉贞
                break;
            case ZW_TIANFU:
                $res = $this->getTianfu($option['zwg']); // 天府
                break;
            case ZW_TAIYIN:
                $res = $this->getTaiyin($option['zwg']); // 太阴
                break;
            case ZW_TANLANG:
                $res = $this->getTanlang($option['zwg']); // 贪狼
                break;
            case ZW_JUMEN:
                $res = $this->getJumen($option['zwg']); // 巨门
                break;
            case ZW_TIANXIANG:
                $res = $this->getTianxiang($option['zwg']); // 天相
                break;
            case ZW_TIANLIANG:
                $res = $this->getTianliang($option['zwg']); // 天梁
                break;
            case ZW_QISHA:
                $res = $this->getQisha($option['zwg']); // 七杀
                break;
            case ZW_POJUN:
                $res = $this->getPojun($option['zwg']); // 破军
                break;
            case ZW_WENCHANG:
                $res = $this->getWenchang($option['szs']); // 文昌
                break;
            case ZW_WENQU:
                $res = $this->getWenqu($option['szs']); // 文曲
                break;
            case ZW_ZUOFU:
                $res = $this->getZuofu($option['nly']); // 左辅
                break;
            case ZW_YOUBI:
                $res = $this->getYoubi($option['nly']); // 右弼
                break;
            case ZW_TIANKUI:
                $res = $this->getTiankui($option['ngs']); // 天魁
                break;
            case ZW_TIANYUE:
                $res = $this->getTianyue($option['ngs']); // 天钺
                break;
            case ZW_LUCUN:
                $res = $this->getLucun($option['ngs']); // 禄存
                break;
            case ZW_TIANMA:
                $res = $this->getTianma($option['nzs']); // 天马
                break;
            case ZW_QINGYANG:
                $res = $this->getQingyang($option['ngs']); // 擎羊
                break;
            case ZW_TUOLUO:
                $res = $this->getTuoluo($option['ngs']); // 陀罗
                break;
            case ZW_HUOXING:
                $res = $this->getHuoxing($option['nzs'], $option['szs']); // 火星
                break;
            case ZW_LINGXING:
                $res = $this->getLingxing($option['nzs'], $option['szs']); // 铃星
                break;
            case ZW_DIKONG:
                $res = $this->getDikong($option['szs']); // 地空
                break;
            case ZW_DIJIE:
                $res = $this->getDijie($option['szs']); // 地劫
                break;
            case ZW_TIANSHANG:
                $res = $this->getTianshang($option['mgz']); // 天伤
                break;
            case ZW_TIANSHI:
                $res = $this->getTianshi($option['mgz']); // 天使
                break;
            case ZW_TIANYAO:
                $res = $this->getTianyao($option['nly']); // 天姚
                break;
            case ZW_TIANXING:
                $res = $this->getTianxing($option['nly']); // 天刑
                break;
            case ZW_TIANKU:
                $res = $this->getTianku($option['nzs']); // 天哭
                break;
            case ZW_TIANXU:
                $res = $this->getTianxu($option['nzs']); // 天虚
                break;
            case ZW_HONGLUAN:
                $res = $this->getHongluan($option['nzs']); // 红鸾
                break;
            case ZW_TIANXI:
                $res = $this->getTianxi($option['nzs']); // 天喜
                break;
            case ZW_SANTAI:
                $res = $this->getSantai($this->getXingyao(ZW_ZUOFU, $option), $option['nlr']); // 三台
                break;
            case ZW_BAZUO:
                $res = $this->getBazuo($this->getXingyao(ZW_YOUBI, $option), $option['nlr']); // 八座
                break;
            case ZW_LONGCHI:
                $res = $this->getLongchi($option['nzs']); // 龙池
                break;
            case ZW_FENGGE:
                $res = $this->getFengge($option['nzs']); // 凤阁
                break;
            case ZW_TIANCAI:
                $res = $this->getTiancai($option['mgz'], $option['nzs']); // 天才
                break;
            case ZW_TIANSHOU:
                $res = $this->getTianshou($option['sgz'], $option['nzs']); // 天寿
                break;
            case ZW_ENGUANG:
                $res = $this->getEnguang($this->getXingyao(ZW_WENCHANG, $option), $option['nlr']); // 恩光
                break;
            case ZW_TIANGUI:
                $res = $this->getTiangui($this->getXingyao(ZW_WENQU, $option), $option['nlr']); // 天贵
                break;
            case ZW_TIANGUAN:
                $res = $this->getTianguan($option['ngs']); // 天官
                break;
            case ZW_TIANFU2:
                $res = $this->getTianfu2($option['ngs']); // 天福
                break;
            case ZW_TAIFU:
                $res = $this->getTaifu($option['szs']); // 台辅
                break;
            case ZW_FENGGAO:
                $res = $this->getFenggao($option['szs']); // 封诰
                break;
            case ZW_GUCHEN:
                $res = $this->getGuchen($option['nzs']); // 孤辰
                break;
            case ZW_GUAXIU:
                $res = $this->getGuaxiu($option['nzs']); // 寡宿
                break;
            case ZW_FEILIAN:
                $res = $this->getFeilian($option['nzs']); // 蜚廉
                break;
            case ZW_POSUI:
                $res = $this->getPosui($option['nzs']); // 破碎
                break;
            case ZW_XIESHEN:
                $res = $this->getXieshen($option['nly']); // 解神
                break;
            case ZW_NIANXIE:
                $res = $this->getNianxie($option['nzs']); // 年解
                break;
            case ZW_TIANWU:
                $res = $this->getTianwu($option['nly']); // 天巫
                break;
            case ZW_TIANYUE2:
                $res = $this->getTianyue2($option['nly']); // 天月
                break;
            case ZW_YINSHA:
                $res = $this->getYinsha($option['nly']); // 阴煞
                break;
            case ZW_JIEKONG:
                $res = $this->getJiekong($option['ngs']); // 截空
                break;
            case ZW_FUJIE:
                $res = $this->getFujie($option['ngs']); // 副截
                break;
            case ZW_XUNKONG:
                $res = $this->getXunkong($option['ngs'], $option['nzs']); // 旬空
                break;
            case ZW_FUXUN:
                $res = $this->getFuxun($option['ngs'], $option['nzs']); // 副旬
                break;
            case ZW_TIANKONG:
                $res = $this->getTiankong($option['nzs']); // 天空
                break;
            case ZW_TIANCHU:
                $res = $this->getTianchu($option['ngs']); // 天厨
                break;
            case ZW_JIESHA:
                $res = $this->getJiesha($option['nzs']); // 劫煞
                break;
            case ZW_TIANDE:
                $res = $this->getTiande($option['nzs']); // 天德
                break;
            case ZW_YUEDE:
                $res = $this->getYuede($option['nzs']); // 月德
                break;
            case ZW_HUAGAI:
                $res = $this->getHuagai($option['nzs']); // 华盖
                break;
            case ZW_XIANCHI:
                $res = $this->getXianchi($option['nzs']); // 咸池
                break;
            case ZW_DAHAO:
                $res = $this->getDahao($option['nzs']); // 大耗
                break;
            default:
                $res = 12;
                break;
        }
        return $res;
    }

    /**
     * 重置索引
     * @param int $index 索引
     * @param int $min 最小值
     * @param int $max 最大值
     * @param int $total 一共多少
     * @return int
     */
    protected function resetIndex($index = 0, $min = 0, $max = 11, $total = 12): int
    {
        if ($index < $min)
        {
            $index += $total;
        } elseif ($index > $max)
        {
            $index -= $total;
        }
        return $index;
    }

    /**
     * 获取十天干文字
     * @param int $index 天干索引 [0,9]
     * @return string
     */
    private function getTianganText(int $index): string
    {
        return $this->tiangan[$index] ?? '';
    }

    /**
     * 获取十二地支文字
     * @param int $index 地支索引 [0,11]
     * @return string
     */
    private function getDizhiText(int $index): string
    {
        return $this->dizhi[$index] ?? '';
    }

    /**
     * 获取紫微星耀名称
     * @param int $index 索引
     * @return string
     */
    private function getXingText(int $index): string
    {
        $config = [
            // 十四正星
            ZW_ZIWEI => '紫微',
            ZW_TIANJI => '天机',
            ZW_TAIYANG => '太阳',
            ZW_WUQU => '武曲',
            ZW_TIANTONG => '天同',
            ZW_LIANZHEN => '廉贞',
            ZW_TIANFU => '天府',
            ZW_TAIYIN => '太阴',
            ZW_TANLANG => '贪狼',
            ZW_JUMEN => '巨门',
            ZW_TIANXIANG => '天相',
            ZW_TIANLIANG => '天梁',
            ZW_QISHA => '七杀',
            ZW_POJUN => '破军',
            // 八吉星
            ZW_WENCHANG => '文昌',
            ZW_WENQU => '文曲',
            ZW_ZUOFU => '左辅',
            ZW_YOUBI => '右弼',
            ZW_TIANKUI => '天魁',
            ZW_TIANYUE => '天钺',
            ZW_LUCUN => '禄存',
            ZW_TIANMA => '天马',
            // 六煞星
            ZW_QINGYANG => '擎羊',
            ZW_TUOLUO => '陀罗',
            ZW_HUOXING => '火星',
            ZW_LINGXING => '铃星',
            ZW_DIKONG => '地空',
            ZW_DIJIE => '地劫',
            // 其他星
            ZW_TIANSHANG => '天伤',
            ZW_TIANSHI => '天使',
            ZW_TIANYAO => '天姚',
            ZW_TIANXING => '天刑',
            ZW_TIANKU => '天哭',
            ZW_TIANXU => '天虚',
            ZW_HONGLUAN => '红鸾',
            ZW_TIANXI => '天喜',
            ZW_SANTAI => '三台',
            ZW_BAZUO => '八座',
            ZW_LONGCHI => '龙池',
            ZW_FENGGE => '凤阁',
            ZW_TIANCAI => '天才',
            ZW_TIANSHOU => '天寿',
            ZW_ENGUANG => '恩光',
            ZW_TIANGUI => '天贵',
            ZW_TIANGUAN => '天官',
            ZW_TIANFU2 => '天福',
            ZW_TAIFU => '台辅',
            ZW_FENGGAO => '封诰',
            ZW_GUCHEN => '孤辰',
            ZW_GUAXIU => '寡宿',
            ZW_FEILIAN => '蜚廉',
            ZW_POSUI => '破碎',
            ZW_XIESHEN => '解神',
            ZW_NIANXIE => '年解',
            ZW_TIANWU => '天巫',
            ZW_TIANYUE2 => '天月',
            ZW_YINSHA => '阴煞',
            ZW_JIEKONG => '截空',
            ZW_FUJIE => '副截',
            ZW_XUNKONG => '旬空',
            ZW_FUXUN => '副旬',
            ZW_TIANKONG => '天空',
            ZW_TIANDE => '天德',
            ZW_DAHAO => '大耗',
            ZW_HUAGAI => '华盖',
            ZW_XIANCHI => '咸池',
            ZW_JIESHA => '劫煞',
            ZW_YUEDE => '月德',
            ZW_TIANCHU => '天厨',
        ];
        return $config[$index] ?? '';
    }

    /**
     * 获取博士十二神名称
     * @param int $index
     * @return string
     */
    private function getBoshiText(int $index): string
    {
        $config = [
            BS_BOSHI => '博士',
            BS_LISHI => '力士',
            BS_QINGLONG => '青龙',
            BS_XIAOHAO => '小耗',
            BS_JIANGJUN => '将军',
            BS_ZOUSHU => '奏书',
            BS_FEILIAN => '飞廉',
            BS_XISHEN => '喜神',
            BS_BINGFU => '病符',
            BS_DAHAO => '大耗',
            BS_FUBING => '伏兵',
            BS_GUANFU => '官符'
        ];
        return $config[$index] ?? '';
    }

    /**
     * 获取长生十二神名称
     * @param int $index
     * @return string
     */
    private function getChangshengText(int $index): string
    {
        $config = [
            CS_CHANGSHENG => '长生',
            CS_MUYU => '沐浴',
            CS_GUANDAI => '冠带',
            CS_LINGUAN => '临官',
            CS_DIWANG => '帝旺',
            CS_SHUAI => '衰',
            CS_BING => '病',
            CS_SI => '死',
            CS_MU => '墓',
            CS_JUE => '绝',
            CS_TAI => '胎',
            CS_YANG => '养'
        ];
        return $config[$index] ?? '';
    }

    /**
     * 获取将前十二神名称
     * @param int $index
     * @return string
     */
    private function getJiangqianText(int $index): string
    {
        $config = [
            JQ_JIANGXING => '将星',
            JQ_PANAN => '攀鞍',
            JQ_SUIYI => '岁驿',
            JQ_XISHEN => '息神',
            JQ_HUAGAI => '华盖',
            JQ_JIESHA => '劫煞',
            JQ_ZAISHA => '灾煞',
            JQ_TIANSHA => '天煞',
            JQ_ZHIBEI => '指背',
            JQ_XIANCHI => '咸池',
            JQ_YUESHA => '月煞',
            JQ_WANGSHEN => '亡神'
        ];
        return $config[$index] ?? '';
    }

    /**
     * 获取太岁十二神名称
     * @param int $index
     * @return string
     */
    private function getTaisuiText(int $index): string
    {
        $config = [
            TS_SUIJIAN => '岁建',
            TS_HUIQI => '晦气',
            TS_SANGMEN => '丧门',
            TS_GUANSUO => '贯索',
            TS_GUANFU => '官符',
            TS_XIAOHAO => '小耗',
            TS_DAHAO => '大耗',
            TS_LONGDE => '龙德',
            TS_BAIHU => '白虎',
            TS_TIANDE => '天德',
            TS_DIAOKE => '吊客',
            TS_BINGFU => '病符'
        ];
        return $config[$index] ?? '';
    }

    private function getDefenText(int $score): string
    {
        // 庙+2、旺+1、平0、闲-1、陷-2
        $config = [
            2 => '庙',
            1 => '旺',
            0 => '平',
            -1 => '闲',
            -2 => '陷',
        ];
        return $config[$score] ?? '';
    }

    private function getDefenText2(int $score): string
    {
        // 庙+3、旺+2、得地+1、利益0、平和-1、不得地-2、落陷-3
        $config = [
            3 => '庙',
            2 => '旺',
            1 => '得',
            0 => '利',
            -1 => '平',
            -2 => '不',
            -3 => '陷',
        ];
        return $config[$score] ?? '';
    }

    private function getWuxingText(int $wx): string
    {
        $config = ['金', '木', '水', '火', '土'];
        return $config[$wx] ?? '';
    }
}
